Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

javascript - Yammer API issue - get groups showing error

I am integrating yammer features in our app (web-front-end stack and using Yammer JS SDK). So, I want get all the groups of a login-ed user.

Inorder to get all the groups, I have tried to call the end points in two ways, /groups.json=mine using SDK - resposne showing method not authorised and www.yammer.com/api/v1/groups.json=mine=1 using normal ajax GET request- throwing access control origin issue.

API is perfectly working, while tested using google chrome browser - by disabling web security.

My question is how I can call www.yammer.com/api/v1/API_END_POINTS without cross origin issue using yammer JS SDK or any other technique?

I found an related answer in this Q & A , but still showing error for me.

Error :

XMLHttpRequest cannot load https://www.yammer.com/api/v1/groups.json?mine=1. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xxx.dev.com' is therefore not allowed access.

Code I have tried after login code :

1# GET Request - return $http.get('https://www.yammer.com/api/v1/groups.json?mine=1')

2# yammer JS SDK -

yam.platform.request({
        url: "groups.json?mine=1",
        method: "GET",
        success: function (group) {
          console.log(group);
        },

        error: function (group) {
          console.error("There was an error with the request.", group);
        }
      });

I have already commented different Q&As for the opinion, but no luck, no one replied.

PS - My all other yammer APIs are working(login, post, message etc), which listed in Yammer REST API Docs, only I am facing problem with APIs hosted in wwww.yammer.com/api/v1, Not api.yammer.com

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should register an App in Yammer dev console, specify allowed origins, get an API key and send it along with request.

See https://developer.yammer.com/docs/api-requests for more info.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...