How do you use the Facebook Graph API in a Google Chrome Extension?

吃可爱长大的小学妹 提交于 2019-12-14 03:49:33

问题


I have been trying to access the information available when using the https://graph.facebok.com/id concept through JSON but have been unable to call or return any information based on different snippets of code I've found around. I'm not sure if I'm using the JSON function correctly or not.

For example,

var testlink = "https://graph.facebook.com/"+id+"/&callback=?";
   $.getJSON(testlink,function(json){
   var test;
  $.each(json.data,function(i,fb){
   test="<ul>"+json.name+"</ul>";
   });
});

In this code, I am trying to return in the test variable the name. When I use this in a Google Chrome Extension, it just returns a blank page.

Alternatively, I've been also trying to use the Facebook Javascript SDK in my Google Chrome extension, but I am unsure what website I should be using when signing up for an API Key.


回答1:


I believe that you need to establish either an OAuth session or provide your API key before you can talk to FB. It's been a while since I messed around with FB api but, I'm pretty sure you have to register before you can use the api.

Here's something that might be useful though, it's a javascript console for Facebook which would allow you to test out your code! http://developers.facebook.com/tools/console/




回答2:


It's an issue with chrome, but I haven't figured out the exact problem. For example open the chrome inspector and type this into it:

$.getJSON("http://graph.facebook.com/prettyklicks/feed?limit=15&callback=?", function(json){console.log(json);});

Then do the same thing in Firefox. Chrome will return nothing, but FF will give you the JSON object. It's not the JSON call itself because if you call something else for instance:

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", function(data) {console.log(data);});

It will come through normally. So there is some miscommunication between chrome and fb. The really confusing part is that if you browse directly to the graph entry by just pasting it into your address bar it will come through normally that way too.



来源:https://stackoverflow.com/questions/4847580/how-do-you-use-the-facebook-graph-api-in-a-google-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!