I am revamping the attachment of our Page Tab app using the "Add Page Tab", and am a little unsure about the flow. This is what I'm trying to do:
1) direct our users to the Add Page Tab dialog with our appId (works)
2) our redirect URL is hit with a post that has the "tabs_added" parameter
3) I use this code to try and get information about the FB account that is getting to my app:
$this->fb = new Facebook\Facebook([
'app_id' => <app_id>,
'app_secret' <app secret>,
'default_graph_version' => 'v2.9'
]);
$tabs_added = PARAM('tabs_added');
If I get a 'tabs_added' parameter, I'm assuming that means someone is "attaching" my app to their page, and I want to get information (specifically UID) for their account:
$helper = $this->fb->getPageTabHelper();
$signedRequest = $helper->getSignedRequest();
This call returns nothing
$parsed_signed_request = FacebookSignedRequest::parse_signed_request( $signedRequest, <app secret> );
This call fails because there is no signed request.
What am I missing? I am using v5 of the Facebook PHP API.
thanks
Related
I am using PHP SDK for creating facebook login, which works fine but when I want to logout and I use getLogoutUrl method which returns logout url in this form:
https://www.facebook.com/logout?next=google.com&access_token=my_access_token
After I redirect to this page I get to the This page is not avalible page on FB and I am not logged out. Any idea what could be wrong ? or it will be SDK bug ? thanks.
I have created a article for facebook login logout with graph api with php. You can see the following code for logout from facebook with php. This is code for logout.php
session_start();
if(isset($_SESSION['fb_access_token'])){
require_once 'php-graph-sdk-5.5/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'app-id', // Replace {app-id} with your app id
'app_secret' => 'app-id-secret',
'default_graph_version' => 'v2.4',
]);
$url = 'https://www.facebook.com/logout.php?next=your-website-return-url/&access_token='.$_SESSION['fb_access_token'];
session_destroy();
header('Location: '.$url);
}
If you need full source code then you can see this link
I've been including the "login with Facebook" product which allows you to get users information based on their Facebook's account email.
So when I try to redirect after the users accept my app on Facebook, it redirects to my homepage, not to the redirect URL I specified on the getLoginUrl() method.
My code is as follows:
$fb = new Facebook([
'app_id' => "my app id",
'app_secret' => "my secret",
'default_graph_version' => 'v2.2'
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email'];
$loginUrl = $helper ->getLoginUrl('http://127.0.0.2/alumn-e/pages/facebookcallback/', $permissions);
$this->set('urlfacebook',$loginUrl);
These are my allowed redirection URIs:
For some reason my users are redirected to http://127.0.0.2/alumn-e/#_=_ when they accept the conditions on the use of my app, when I was expecting to get a redirection to http://127.0.0.2/alumn-e/pages/facebookcallback/.
I've been searching on google lots of time and I can't understand why.
EDIT: I've included error_reporting on my function and I've done the process of logging on fb and it doesn't show anything on the console.
I discovered this was a mistake on my facebook callback function so thanks to everyone! I finally understood this and I used v2.8 finally.
start from beginning,i fetched Facebook Page id,access token,user access token,user id user emails,means i have lot of information about a facebook user profile and pages details,now i want to fetch conversations messages between user and page,i have all privilege to read message and i get messages through graph api explorer but its quite different to implement with programmatically.
so if anyone have knowledge how to get messages with php sdk code then please update me. thanks in advanced.
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.4'
]);
$fb->setDefaultAccessToken({access-token});
$responsePosts = $fb->get('me?fields=feed{id,message,full_picture}');
$postsNode = $responsePosts->getGraphNode();
var_dump($postsNode);
I'm trying without success for 2 days now to retrieve page feed with Facebook PHP SDK. Details :
I got a user, who is page admin
I created an app (not public, is that a problem?)
I use an AJAX called PHP script to try to retrieve feed, because I don't want to pollute main page loading.
All stuff given on PHP SDK doc is related to manual login and access token retrieval.
I Managed to retrieve a user token using the 2-scripts code (login, and callback), with manage_pages speical grant require :
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['manage_pages']; // Optional permissions
$loginUrl = $helper->getLoginUrl('http://domain.com/fb_callback.php', $permissions);
How can achieve the same thing without manual redirection, is one script, in AJAX context? SHould I use Curl to emulate manual redirection?
THing which puzzle me out is that the same stuff tok 2 lines using JS framework :
window.fbAsyncInit = function() {
// Framework init with Vinexpo app ID
FB.init({
appId : '012345789',
xfbml : true,
version : 'v2.4'
});
// Check status
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// If connected, get last 2 posts on Facebook page
FB.api(
"/page_ID/posts?limit=2",
{
access_token : response.authResponse.accessToken
},
function (responsePost) {
if (responsePost && !responsePost.error) {
// Fill tiles on social network panel
}
}
);
}
});
Thanks in advance for answers or leads.
If you just want to read the newsfeed of one of you pages via AJAX, you don't necessarily need the PHP SDK if you generate yourself an eternal page access token and use this for your plain HTTP requests.
Have a look at my answer here on how to get such a token:
Post to a facebook page without "manage_pages" permission using php
IDEA: Get event information without user interaction from various facebook pages (clubs,bars,etc..). However some pages have set that info not to be public.
WORKING PRINCIPLE: I have the latest facebook PHP-SDK on my site and an APP on facebook, so usually i call
$facebook = new Facebook(array(
'appId' => '387262991341732',
'secret' => '09014d999f6e34d80ca3e62e331834cc',
));
$events = $facebook->api("$page_url/events");
PROBLEM:
When a page is not public I have to use an access_token.
1) This is an APP access-token, which is not permitted to view the events.
$app_token = $facebook->getAccessToken();
So I figure I need to get user access_token and add more code:
if (!$user) {
$args['scope'] = 'offline_access';`<br>`
$loginUrl = $facebook->getLoginUrl($args);`<br>`
}
<?php if (!$user): ?>
Login with Facebook
<?php endif ?>`
I click the link by myself and use getAccessToken() to get the user access_token:
$user_token = $facebook->getAccessToken();// I store this in my database
I check this with:
file_get_contents('http://graph.facebook.com/privatepage/events?access_token=$user_token');
// Everything works, im very happy
2) Now I delete all cookies, etc and try to use $facebook->setAccessToken($user_token) and then $events = $facebook->api("$page_url/events"); and get nothing. I assure you one more time that AccessToken is valid.
After quite a long research im stuck with this.
???) *Any Ideas how use $facebook->api(...) and not file_get_contents?