FaceBook downloading photos using php-sdk
I am new to Facebook PHP SDK for the Graph API.
I have created an application on Facebook and I got the application id, secret ..etc. I also got the access code with some permissions using the scope parameter.Using that code I got the access token with offline access.
https: //graph.facebook.com/oauth/access_token?client_id=xxxxxxxxxx&redirect_uri=http://192.168.15.5/xxxx/facebook/&client_secret=xxxxx&grant_type=client_credentials.
Using this I got the access token. Now my Question is that I want to access the user information such as photos and friend lists
I do not know if it is correct or not,
https://graph.facebook.com/me/friends?access_token=xxxxxxxxxxxxxxxxxxxxx
when I use this it says,
"{
"error": {
"type": "OAuthException",
"message": "An active access token must be used to query information about the current user."
}
}"
How can I access the user information, by using the access token of that user. I want to access the user information from the application at anytime for the user who has allowed my application to 开发者_如何学JAVAaccess his information.
If you use the Facebook PHP SDK (see on github), you should not call these URL directly but only call functions of the SDK.
See this answer to see how to fetch and use the offline access token to make API calls : How to login with offline_access using the new Facebook PHP SDK 3.0 ?
Then to get the user friends and their photos, you will call :
$args = array("fields" => "name,picture");
$friends = $facebook->api('/me/friends', $args);
Then the array $friends['data']
will contain the URLs of the pictures of the friends :
Array(
[0] => Array(
[name] => Quentin Pleplé
[id] => 1536397056
[picture] => http://profile.ak.fbcdn.net/...jpg
)
[1] => ...
...
)
Hope that helps !
精彩评论