I am following the instructions on this page to create a PHP script which will (hopefully) allow me to post to Facebook from my web site.
All I really want to establish is the ability to enter text and a link into a form on my web site and have it be posted to a Facebook wall.
My understanding is that I need to validate a Facebook app in order to do this, which is what brought me to the above web page.
I have followed their instructions dutifully, and by now I have been through it many times, checking to make sure I have followed their steps accurately.
However, when it gets to the part where I run fb_access.php from my web site, I get absolutely no response from Facebook.
I notice that the screen shot examples on the page I am using are not what I am seeing in the Facebook interface. The tutorial is from December 2010, which I would hope is recent enough, but perhaps things have changed...?
How do I get Facebook to respond to my PHP script?
<?
require_once 'facebook.php';
$app_id = "<my App ID";
$app_secret = "<my App Secret>";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
if(is_null($facebook->getUser()))
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
exit;
}
?>
Try using the Facebook PHP SDK demo script here:
https://github.com/facebook/php-sdk/blob/master/examples/example.php
Once you have this script running - you can then begin to request calls, such as post to wall. If the call is successful, FB will prompt you with a Request for Permission.
Related
first facebook asks me to click okay to authorize the app then chrome gives me this error. and the I have this endless redirect problem. I have read many cases about this but none clear and simple enough to get me over this obstacle.
The webpage at __________&redirect_uri=http%3A%2F%2Fmizu.net46.net%2Ffacebookpost6.php&state=_________________&sdk=php-sdk-3.2.3&req_perms=user_status%2Cpublish_stream%2Cuser_photos%2Coffline_access%2Cmanage_pages#=">https://www.facebook.com/dialog/oauth?client_id=__________&redirect_uri=http%3A%2F%2Fmizu.net46.net%2Ffacebookpost6.php&state=_________________&sdk=php-sdk-3.2.3&req_perms=user_status%2Cpublish_stream%2Cuser_photos%2Coffline_access%2Cmanage_pages#= has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
what I know.
facebook.php is working
the secret and appid are being passed correctly by the script.
I must have configured my app settings on the facebook development site almost correctly
how do I know this?
because when I change those variables in my script or adjust the settings
on facebook development server, I dont even get this far, I dont get asked to click ok or see my facebook profile in chrome.
what I dont know.
How to fix this redirect problem. or complete the authentication process. echo $user always returns 0.
my code looks like this:
require 'src/facebook.php';
$app_id = "xxxxxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' =>
'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
thanks for any help
changing the setting to no when asked" is this a desktop app? " in the advanced section of app configuration on developers.facebook.com seem to resolve this issue.
So I want to implement Facebook login on my site. I have dowloaded the SDK, created an app and pasted the app id and secret in.
The problem I am getting is that, while the login flow appears to work and I am getting values returned ok from
facebook->getUser()
and
facebook->getAccessToken()
Calls to
$user_profile = $facebook->api('/me','GET')
throw an exception saying I have no access token.
Since this is unmodified example code straight from the SDK I'm kind of at a loss - if the coding example given doesn't work how am I supposed to figure anything out? :)
Same issue with the code on this page:
https://developers.facebook.com/docs/php/howto/profilewithgraphapi/
Basically that does the same thing but handles the exception so I go round and round in a "login to facebook" loop.
I can see the app added to the list in my facebook profile OK when I log in so that side appears to be working. It seems that either the SDK is broken or the access token I'm getting back is for some reason not valid.
Any help or pointer as to what I've missed would be much appreciated!
Thanks
Justin
Try this
$config['cookie'] = true;
and relogin.
This is from the PHP code I use to login.
Here is the complete flow of the code hope this helps.
Say the page for the FB connect is login.php and I will have the following PHP code on the top of the page
require_once 'src/facebook.php'; //include the facebook php sdk
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_APP_SECRET,
'cookie' => true,
'domain'=> FACEBOOK_CONNECT_DOMAIN
));
$user = $facebook->getUser();
if($user){
// lets set the access token before making a api call.
$new_access_token = $facebook->getAccessToken();
$facebook->setAccessToken($new_access_token);
$user_profile = $facebook->api('/me','GET')
......
......
}else{
// display the fb login
}
I'm working on a problem for many days now without solution.
What I got :
A MySQL database with 1000+ advices
A daily advice displayed on a page with a PHP script
A FB Application + FB SDK
A FB user account
What I'm looking for :
A daily post from my FB account containing the daily advice
The best result I got so far :
A php page which post the daily advice by clicking on a button then login in FB.
Is it possible to save the login informations in the PHP script to get a fully automatic daily post with cron ?
Does anyone know a solution ?
Sincerly,
Ok folks, I did it.
Here is my solution :
1) Download the Facebook PHP SDK from https://github.com/facebook/facebook-php-sdk
2) Generate an extended access token with this code (generate_token.php) :
require_once('src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'YOUR APP ID',
'secret' => 'YOUR APP SECRET ID',
'fileUpload' => true
));
$facebook->setExtendedAccessToken();
$access_token = $_SESSION["fb_".$fb_appId."_access_token"];
$facebook->setAccessToken($access_token);
$accessToken = $facebook->getAccessToken();
The $accessToken is a 60 days long access to your account by the application.
Store this token in your database.
3) Publish script (fb_post.php):
Get the $accessToken from your database, then use it to access to your account without manuel login :
require_once('src/facebook.php');
$app_id = 'YOUR APP ID';
$app_secret = 'YOUR APP SECRET ID';
$config = array(
'appId' => $app_id,
'secret' => $app_secret,
);
$facebook = new Facebook($config);
$facebook->setAccessToken($fbAccessToken);
$user_id = $facebook->getUser();
Use the first page (generate_token.php) once every 2 months to generate a 60 days token.
"Et voila", just configure a daily Cron Job which execute "fb_post.php" and your robotic Facebook will rise !
did you try facebook SDK for PHP, it is simple you have to register your app with facebook and use your application id and application secret following link contains a sample script.
developers.facebook.com/docs/php/howto/postwithgraphapi
1.You need your Website to set as an Facebook App
2.read into https://developers.facebook.com/docs/opengraph/
Basicly it is possible of course. But it for me it needs time to get used to the Graph Api.
means a quick answer for your desire is not possible
Im trying to retrieve data from
http://www.facebook.com/ajax/shares/view/?target_fbid=410558838979218&__a=1
I get mix of js and html with sharing information if I open this link through my browser, but if I use
$url = 'http://www.facebook.com/ajax/shares/view/?target_fbid=410558838979218&__a=1';
$html = file_get_contents($url);
I get
"Not Logged In","errorDescription":"Please log in to continue.","payload":{"_dialog":{"title":{"_html":"Not Logged In"},"body":{"__html":"Please log in to continue.................
and etc
I understand that i need to be logged in, i tried login through facebook api:
$config = array(
'appId' => '**********',
'secret' => '**********',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
Im gettin user and etc, everything's okay, but retreiving share information fails anyways
How can I "properly" login to solve this issue?
Thanks
You're using the SDK initialisation code but trying to scrape facebook.com's web interface - these are not compatible things
You'd need to automate the login to facebook.com via your code as well and handle all the cookies if you want to scrape, buy doing so is explicitly against Facebook's TOS and could get you in legal trouble if you persist
I have an app called static HTML (https://apps.facebook.com/static_html_plus/?ref=ts) installed on a page of mine..
I want to be able to access getSignedRequest() to pass data through the URL in facebook using app_data.. (I want to be able to pass an item id to activate a JS item in the iframe.. in essence allowing me to link to an expanded JS feature in the page)
The issue is that i am recieving NULL from getSignedRequest(); I am not sure if the app I am using (mentioned above : static HTML) is stopping the information from getting passed through to my iframe.
If you are unfamiliar with this app, it allows you to put HTML/CSS/JS to embed an iframe.
On the hunch that it is the app that is stopping the propagation of the facebook data to my iframe, I have attempted to follow SEVERAL tutorials, both video and written that try to create a facebook iframe by creating a custom app.. none have worked, and i have not been successful in even adding a BASIC TAB to any of my pages..
I am about to give up on this facebook thing as every tutorial I have found has a completely different looking interface or set of instructions then what is ACTUALLY available on the facebook developers page..
Does anyone have a CLEAR UP-TO-DATE, non-facebook written walk-through, or atleast know if my use of the static HTML app is what is causing me to recieve null in my getSignedRequest()?
Here is my php code in the iframe i embed in the static HTML app, incase you think the error is in there somewhere.
require 'facebook.php';
//facebook signed app_data
$app_id = "xxxxxx";
$app_secret = "xxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get contents of signed request
$signed_request = $facebook->getSignedRequest();
Any help would be nice. I have wasted 2 nights on this crap.
.html files cannot accept HTTP POSTs unless the web-server is configured to accept this verb. However, the only way to get at the post parameters is with server-side code and cannot be done clientside.