[英]Facebook API - Retrieve my own albums and photos
I'm trying to retrieve my albums and photos from facebook using the Facebook api for php. 我正在尝试使用PHP的Facebook API从Facebook检索我的相册和照片。 I've created an app now i have my AppId and my AppSecretId. 我已经创建了一个应用程序,现在有了我的AppId和AppSecretId。 I don't need any login window because I want to display my own photos, not the ones from any other user, but everytime I try to retrieve them, I receive this message "An active access token must be used to query information about the current user." 我不需要任何登录窗口,因为我想显示自己的照片,而不是其他任何用户的照片,但是每次尝试检索它们时,我都会收到此消息“必须使用活动访问令牌来查询有关当前用户。”
I know that if I were going to show the photos from another users, then I should ask for their login and then generate the access token, but this is not the case. 我知道,如果我要显示其他用户的照片,那么我应该要求他们登录,然后生成访问令牌,但事实并非如此。
I have tried generating an App token and tried to use this as an access token but it's not working either. 我尝试生成一个App令牌,并尝试将其用作访问令牌,但是它也不起作用。
This is the code I'm using: 这是我正在使用的代码:
require_once("facebook/facebook.php");
try{
$facebook = new Facebook(array(
'appId' => '<APPID>',
'secret' => '<SECRETID>',
'cookie' => true
));
echo($facebook->getUser());
if(is_null($facebook->getUser()))
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
exit;
}
$me = $facebook->api('/me');
$albums = $facebook->api('/me/albums', array('access_token' => $facebook->getAccessToken()));
echo($albums);
}catch(Exception $e){
echo "THIS IS THE ERROR: " . $e->getMessage();
die;
}
I hope you can help me with this. 希望您能帮到我。 Thank you so much!! 非常感谢!!
The easiest way to generate a Facebook access token for your personal account is to visit their Graph API Explorer. 为您的个人帐户生成Facebook访问令牌的最简单方法是访问其Graph API Explorer。 It will automatically generate an access token that you can copy/paste into your code. 它将自动生成一个访问令牌,您可以将其复制/粘贴到您的代码中。
https://developers.facebook.com/tools/explorer https://developers.facebook.com/tools/explorer
Additionally, you can use the 'Get Access Token' button on that page to request an access token with specific permissions. 此外,您可以使用该页面上的“获取访问令牌”按钮来请求具有特定权限的访问令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.