I created a php module for Drupal that pulls a public album and display pictures inside it. I discovered that the module suddenly stopped working. I googled and looks like even a public album requires an access token now. I see access token field on https://developers.facebook.com/tools/explorer/?method=GET&path=10150146071791729
In this case, how do I fix this problem? It looks like even offline_access is gone now.
Do I must ask users to accept a certain permission? What permission? It's a public pictures.
Ok, found an answer.
You need to create an app and get an app id and a secret key.
Once you have those two, download Facebook PHP SDK on https://github.com/facebook/facebook-php-sdk.
Sample Code:
require_once "facebook.php";
$facebook = new Facebook(array(
'appId' => 'appid',
'secret' => 'securet',
));
$token = $facebook->getAccessToken();
$json = file_get_contents("https://graph.facebook.com/293849234?access_token=".$token);
Related
I have a web service that servers Android, IOS and Windows Phone. Each app connects to Facebook using native SDK and passes the fb_user_id and access_token when performs API's requests. The API should retrieve the user and friends details and save them on MySQL.
The system works fine, except that it can't return friend's retionship, location and birthday.
$fb = new Facebook([
'appId' => my_app_id,
'secret' => my_app_secret
]);
$r = $fb->api("$fb_user_id/?fields=friends.fields(relationship,birthday,location)&access_token=$access_token");
var_dump( $r );
My app on Facebook has friends_relationships, friends_location and friends_birthday permissions. When we test using a Facebook user setted as developer, the app returns all the information, but when a non-developer uses we can't return those informations.
Any idea?
I figured what happened!
Facebook's SDK generates a token for /me. In PHP I was calling fb_user_id?fields=friends.fields(id,name,birthday,etc). But requests with /fb_user_id can't return info with a /me generated token.
It works when used directly on browser https://graph.facebook.com/me?fields=friends.fields(id,name,birthday,etc), but fails when called by Facebook's PHP class:
An active access token must be used to query information about the current user.
My solution:
$url = "https://graph.facebook.com/me?fields=id,name&access_token=$this->access_token";
$this->me = file_get_contents ( $url );
$json = json_decode($this->me, true);
For further information, checkout this answer. New ideas are welcome.
I am trying to pull some statuses in json format from Facebook's Graph API. Since i am using PHP, so I went for the following library.
https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php
I saw the example, and the class requires some arguments upon instantiation, and I just don't know what they are:
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '344617158898614',
'secret' => '6dc8ac871858b34798bc2488200e503d',
));
And also from the Graph API Explorer I see the access_token, but this PHP library doesn't mention it at all, I thought I need the access_token to make requests, don't I? I hope someone can clear things up for me.
Yes you require an access_token to query on behalf of user on Facebook, it can either be an App access token or User access token. If the user authorizes your app, with required permission which in your case would be read_stream permission, then you can obtain his access token and query for status updates. The default access token is your App access token which can access only public data.
Also I would suggest you to to over the PHP SDK documentation for getting started with it.
I am creating a web application using php. I have a closed group in facebook. When a user login to my application I am showing them a page. I want to stream data grom my facebook group and display in that page. Since this is a closed group I am not able to stream data from that using php SDK. I am using the following code.
This code workes if the group is public.
$facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_SECRET_KEY, 'cookie' => true,));
return $facebook->api('/' . FB_GROUP_ID . '/feed');
I think that we have to pass access token with extended permission to get that data. But how to generate that token without user intevention ?
Any Ideas?
i'm working with the facebook sdk for php and want the users to sit on my own database but still to get permissions of them.
my very basic use of the
i want to register users to my site via facebook, but i still want to be able to post to thier wall. i thought about only using the facebook login method but then i have no way to ask my customers (Via registration) what is their phone number and the phone number is the most important part i need from the people who register.
i tried to add the scope params to my <fb:registration tag but it seems to ignore it. when i only use the login method via <fb:login-button the permissions issue seems to work.
this is my exact flow:
first, i call the fb:login-button to determine if the client is already reistered:
<fb:login-button scope="publish_stream,user_checkins,email" registration-url="/register" /></fb:login-button>
then, on the registration page i have this code:
<fb:registration
fields='[{"name":"name"},{"name":"gender"},{"name":"email"},{"name":"birthday"},{"name":"location"},{"name":"phone2","description":"mobile phone","type":"text"}]'
redirect-uri="XXXXXX"
fb_only="true"
scope="read_stream,publish_stream"
width="530">
when the user comes back from facebook i use this code:
require_once('facebook-sdk/src/facebook.php');
$facebook = new Facebook(array( 'appId' => $GLOBALS['facebookAppID'], 'secret' => $GLOBALS['facebookAppSecret']));
$customerArray = $facebook->getSignedRequest();
that's works great and create the customer record on my database. but - it does not give the permission i need to post on my user wall.
You can't ask for user permissions in registration using this plugin, but you can do a work around asking for permissions before showing the form. You can make a call to FB.login popup and after the user gives you permissions in the callback function you can show the registration form (which could be hidden while the user accept the permissions).
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 access 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 !