简体   繁体   English

Ajax Facebox中的Facebook PHP API

[英]Facebook php api in Ajax facebox

I'm trying to load some php fql calls in to an ajax facebox (its like lightbox), i include a file with the following code in, but it does not work without the redirect ($my_url), is there any way to make the code ignore the redirect? 我正在尝试将一些php fql调用加载到ajax facebox(类似于lightbox)中,我包含了一个包含以下代码的文件,但没有重定向($ my_url)它就无法工作,有什么方法可以使代码忽略重定向? Or do i need to use the javascript sdk from facebook? 还是我需要使用来自Facebook的javascript SDK?

$app_id = 'APP ID';
$app_secret = 'APP SECRET';
$my_url = 'LINK HERE';

$code = $_REQUEST["code"];

$bruger = "me()";

//auth user
if(empty($code)) {
    $dialog_url = 'https://www.facebook.com/dialog/oauth?client_id=' 
    . $app_id . '&redirect_uri=' . urlencode($my_url) ;
    echo("<script>top.location.href='" . $dialog_url . "'</script>");
}

$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
    . $app_id . '&redirect_uri=' . urlencode($my_url) 
    . '&client_secret=' . $app_secret 
    . '&code=' . $code;

// response is of the format "access_token=AAAC..."
$access_token = substr(file_get_contents($token_url), 13);

Have you tried using the Facebook PHP SDK ? 您是否尝试过使用Facebook PHP SDK I highly recommend moving away from depreciated FQL as once you get to grips with the new API it is very easy to use 我强烈建议您不要使用已贬值的FQL,因为一旦您掌握了新的API,它就很容易使用

Once you have set up $facebook you can then just make API calls with $facebook->api('/query'); 一旦设置了$facebook您就可以使用$facebook->api('/query');进行API调用$facebook->api('/query');

I'm not 100% sure what information you are trying to retrieve from your question however but I have put together a Lightbox / Facebook myself, even using tag data to pick people out of the picture so feel free to provide more detail and I will try to provide a more comprehensive answer 我不是100%不确定您要从问题中检索什么信息,但是我自己整理了一个Lightbox / Facebook,甚至使用标记数据从图片中挑选人物,因此随时提供更多详细信息,我会尝试提供更全面的答案

EDIT: In order to build queries and test data returned you can use the Graph API Explorer and construct the query you want to test against your own Facebook Application 编辑:为了构建查询和测试返回的数据,您可以使用Graph API Explorer并构建要针对自己的Facebook应用程序进行测试的查询

I'm trying to fetch friendlist 我正在尝试获取朋友列表

After you've setup $facebook then you can retrieve your friends by using 设置$facebook之后,您可以使用来检索您的朋友

$fb_friends = $facebook->api("/me?fields=friends");

Next: 下一个:

50 latest tagged photos and likes 50张最新标签和喜欢的照片

To retrieve the latest 50 tagged photos and likes you'll need to do: 要检索最新的50张带标签的照片和喜欢的照片,您需要执行以下操作:

$fb_photos = $facebook->api("/me?fields=photos.limit(50)");
$fb_likes = $facebook->api("/me?fields=likes.limit(50)");

// I should mention that each time api() is called, the server makes a HTTPS request to Facebook, so it is worth condensing api queries to reduce load time:
$fb_data = $facebook->api("/me?fields=photos.limit(50),likes.limit(50)");

$fb_photos = $fb_data['photos'];
$fb_likes = $fb_data['likes'];

If you want the latest 50 of photos and likes chronologically sorted, you can array_merge() the two arrays and use a subval sort function for created_time, then just take the first 50. 如果您希望按时间顺序对最新的50张照片喜欢的照片进行排序,则可以将两个数组array_merge()并使用一个subval排序函数作为created_time,然后仅获取前50张照片。

I'm going to insert all the basic info into mysql (stuff like name, facebook id, email ect.) I'm going to use the fb id inserted into myslq, to view the friendlist, likes and photos 我将所有基本信息插入mysql(诸如名称,facebook id,email等之类的东西)。我将使用插入myslq的fb id来查看好友列表,喜欢和照片

Right then, when you user logs on you will need to request extended permissions from them to access data like photos, likes and friends. 届时,当用户登录时,您将需要向他们请求扩展权限,以访问照片,喜欢和朋友之类的数据。 When your user logs into facebook with the link you provide to them on your website, you need to call 当用户使用您在网站上提供给他们的链接登录到Facebook时,您需要致电

$loginUrl = $facebook->getLoginUrl(array( 'scope' => 'read_stream,user_likes,user_photos,friends_photos,user_friends'));`

The scope is defined by the permissions stated here 范围由此处所述的权限定义

Once you have been granted access to that information by the user you can retrieve profile information with $user = $facebook->api("/me"); 一旦用户授予您对该信息的访问权限,您可以使用$user = $facebook->api("/me");检索配置文件信息$user = $facebook->api("/me"); and store the facebook ID, name etc in your database. 并将facebook ID,名称等存储在数据库中。

To get a better look at the data you'll be handing for photos then make sure that you click Get access token at the top of the page and grant permission to access photos and likes 为了更好地查看要处理的照片数据,请确保单击页面顶部的“ 获取访问令牌” ,并授予访问照片和喜欢的图片的权限

Any more questions feel free to ask and I will provide more detail, hope that helps mate! 如有其他问题,请随时提出,我将提供更多详细信息,希望能对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM