开发者

Get photos with graph api

I've read a lot of tutorials/articles/questions here about this, as well as trying to find something useful in the fb documentation.

So far I've made no progress at all myself so any input would be greatly appreciated, I'm simply trying to access a list of my photos but all I get is an empty array.

I know I've added more req_perms than I need probably, I just copied the ones from a "working tutorial" that didnt work for me, and after reading a thread here I also added user_photo_video_tags because that had worked for the thread poster (again, not me).

I've gotten the dialog to allow photos sharing my photos with my app, login works without any problems, the access token I get seem to be correct, after logging in I have visited:

https://graph.facebook.com/me/photos?access_token= and the token, and gotten an empty array, if I wasnt logged in or the access_token wasnt linked to my app there would be some error, but all I get is an empty array.

Thanks in advance for any input.

Thanks to Chaney Blu I was able to validate my permissions:

{
   "data": [
      {
         "installed": 1,
         "status_update": 1,
         "photo_upload": 1,
         "video_upload": 1,
         "create_note": 1,
         "share_item": 1,
         "publish_stream": 1
      }
   ]
}

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once 'library/fa开发者_开发百科cebook.php';

$app_id = "xxxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

$loginLink = $facebook->getLoginUrl(array(
    'scope' => 'user_status,publish_stream,user_photos,user_photo_video_tags'
));
$logOutLink = $facebook->getLogoutUrl();

$user = $facebook->getUser();

if ($user) {
    try {
        // User logged in, get token
        $token = $facebook->getAccessToken();
        //var_dump($token); dumped successfully
        // Get public profile info
        $user_profile = $facebook->api('/me');
        //var_dump($user_profile); dumped successfully
        $photos = $facebook->api('/me/photos?access_token=' . $token);
        var_dump($photos); // Empty array, BAH!
    } catch (FacebookApiException $e) {
        $user = null;
    }
}

?>
<a href="<?php echo $loginLink; ?>">Click here to login if you aren't autoredirected</a><br /><br /><br />
<a href="<?php echo $loginLink; ?>">Click here to logout</a>


Not sure if this is the problem, but try this. It appears you're using the latest PHP SDK. In your getLoginUrl(); calls, try changing 'req_perms' to 'scope'.

Like this:

$loginLink = $facebook->getLoginUrl(array(
    'scope' => 'user_status,publish_stream,user_photos,user_photo_video_tags'
));

You can verify that you've authorized the correct permissions by visiting https://graph.facebook.com/me/permissions/?access_token=XXXX


After testing some other permissions I noticed facebook weren't updating the permissions to my token, even when logging out of the app, logging in again and accepting new permissions nothing changed when I looked at the Graph permissions link I got from Chaney Blu.

I used that link to verify the token from facebooks graph api page http://developers.facebook.com/docs/reference/api/ and noticed that token had access to user_photos but not my token.

Going into my facebook settings and removing the app made facebook update my permissions the next time I signed into the app.

Thanks to Chaney Blu for putting me on the right track. Would vote you up if I had the reputation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜