I'm trying to use dialog/OAuth to get the code parameter from Facebook in order to get the token
When I try to log in using generated URL, I get a blank page.
I'm using this code to generate the url
sprintf('https://www.facebook.com/v15.0/dialog/oauth?%s', http_build_query(array(
'client_id' => self::FACEBOOK_APP_ID,
'state' => 'op=add-page',
'scope' => 'pages_show_list,pages_manage_metadata,pages_read_engagement',
'auth_type' => 'rerequest',
'redirect_uri' => url(self::FACEBOOK_APP_REDIRECT_URI),
)));
Url Example
https://www.facebook.com/v15.0/dialog/oauth?client_id=369956434515590&state=op%3Dadd-page&scope=pages_show_list&response_type=code&auth_type=rerequest&redirect_uri=https%3A%2F%2Ftest.com%2Fapi%2Ffacebook%2Fauth
how can I make the dialog appear for approval, so I can get the code parameter
I just needed to add the redirect url in Valid OAuth Redirect URIs
1- go to Facebook Login for business
2- settings
3- add the url in Valid OAuth Redirect URIs
I hope it will help someone
Related
I've created and stored permanent facebook page access tokens. Must I still use a user access token each time I want to post to a fb page feed, or can I use only the page access token?
Here is command I'm using to setup the post now:
$page_post = (new FacebookRequest( **$session**, 'POST', '/'. $page_id .'/feed', array(
'access_token' => $access_token,
'name' => 'Randy Steel',
'link' => 'http://www.LIPSapp.com/',
'caption' => 'Example text',
'message' => 'This is my link!',
) ));
Where $session holds the user access token and $access_token holds the permanent page access token.
If, because I have the perm page access token, I can skip getting/updating the
user access token (60 days at best), how would the above command change?
What would the value of $session need to be, or can that parameter be omitted?
Thanks in advance for any help.
With Facebook's new update like 2 years ago, pages acts like normal profile pages. So you only need access tokens of page not administrator's. Access tokens can be changed overtime or can be expired so it's best you to store administrators access token just in cas the access key losts its validity.
If you always want to post "as Page", you can use the stored Page Token - in fact, you HAVE to use the Page Token to post "as Page". You only need the User Token once, for getting an Extended Page Token.
I would not even use the PHP SDK for that, basic CURL calls are good enough. A small example of using CURL with the Facebook API can be found here: http://www.devils-heaven.com/extended-page-access-tokens-curl/
My situation is the following.
I am the owner of a facebook app,and a facebook page.I would like to programatically(from code) post to this facebook page.
As far as I know I need a facebook app to do that so I created one.
I am using the facebook php sdk and code igniter.(I am not using the javascript sdk).
I have the facebook object.I printed it's methods and tried printint the user id while I was logged into facebook.
This did not work.
My questions are the following:
1)Why does it not work to print the facebook id?
2)What is the most simplest solution to programatically post to my facebook page ?(from my app,or from my user)
What am I doing wrong ?
This is my code
$config = array(
'appId' => 'xxxx',
'secret' => 'xxxx',
'cookie' => true,
);
$this->load->library('facebook', $config);
echo '<pre>';print_r(get_class_methods($this->facebook));
$id = $this->facebook->getAppId();
$secret =$this->facebook->getApiSecret();
$uri = "http://tipsterscorner.com/stats/display/facebook1";//callback_url se pare ca nu e bun
//i build the facebook url.If I use this in the browser ,I get a series of popups(do you allow the application to blabla)
//I read somewhere that if I change the last parametere to code,and use curl,I will get the token in the response
//printed on the screen of the return url,but that does not happen
$facebook_url = "https://www.facebook.com/dialog/oauth?`client_id=$id&client_secret=$secret&redirect_uri=$uri&scope=publish_stream,offline_access,read_stream,manage_pages&response_type=token";`
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $facebook_url,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
This is the url.
http://tipsterscorner.com/stats/display/facebook1
Thank you very much.
To post on facebook by yourself and on behalf of other's using the app you need to obtain user access token. There are two kinds of Access Tokens namely App Access Token and User Access Token. When app is posting on user's behalf User Access Token is required. User Access Token is generated when a User gives permissions for the app(The dialog popup which you experienced when entering the facebook url in browser). Its solely upon user whether or not to grant permission to the app to post on their behalf. App should be developed to handle both the situations. Once User have given permission(Basic Permission which includes all publicly available info of the user), user access token will be generated. You can either store it in database table or in SESSION. Sometimes user access tokens may become invalid and new token has to be retrieved. During that time curl can be used to retrieve because user has already granted permission for the app.
http://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/
Hi ive set a news facebook application like below but when i call the auth dialog the Email is not requested so i dont get any informations..
http://hpics.li/b91d453
Any idea ?
My FB request :
$data['get'] = array(
'access_token' => $access_token,
'locale' => 'fr_FR',
'req_perms' => 'email,user_about_me,user_birthday,user_location,publish_actions',
'ext_perms' => 'publish_stream',
'fields' => 'email,name,picture,first_name,last_name,gender,link,birthday,email,location'
);
And the PermissionDialog dont contain the email and the req_prems.. Why ?
And also Preview Current Dialog is different than Preview referal dialog (which contains emails etc)..
Any idea ?
Which documentation are you working from? The parameter that needs to be passed to the Auth dialog to request additional permissions changed to 'scope' in October 2011
See https://developers.facebook.com/docs/authentication/permissions/ for the permission info and https://developers.facebook.com/docs/authentication/ for how to authenticate
If you're doing server-side auth the URL to redirect the user to is:
https://www.facebook.com/dialog/oauth/?
client_id=YOUR_APP_ID
&redirect_uri=YOUR_REDIRECT_URL
&state=YOUR_STATE_VALUE
&scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
And then you exchange the code for a token using the oauth endpoint (all this is covered in the docs above) - which your server makes a request to using the parameters below:
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID
&redirect_uri=YOUR_REDIRECT_URI
&client_secret=YOUR_APP_SECRET
&code=CODE_GENERATED_BY_FACEBOOK_AND_SENT_TO_YOUR_APP_IN_EARLIER_STEP
I want the user to be redirected to a particular webpage after logging in using Facebook. I created a LoginUrl using Facebook PHP SDK and the user clicks on this link to log in. I followed http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ when using the $facebook->getLoginUrl()
Problem: If I were to include the redirect_uri parameter, Facebook gives me an error An error occurred. Please try again later. The login url works fine without including the redirect_uri.
Anyone knows how to fix this? Thanks!
Non-working PHP Code
$loginUrl = $facebook->getLoginUrl(array(
"scope" => "email,user_education_history,user_work_history",
"redirect_uri" => "http://mydomain.com/login/facebook"
));
Working PHP Code
$loginUrl = $facebook->getLoginUrl(array(
"scope" => "email,user_education_history,user_work_history",
));
I had this same exact problem. FB changed the parameter from redirect_url to next from v2 to v3, and is poooooorly documented. Try next, should work for you.
It's pretty old topic, but here is the solution I've found working, if someone reads it later... First thing is that you have missed the comma after "redirect_uri" in your "Non-working PHP Code". And if you have "App on Facebook" selected in your application settings (app in Canvas) then your redirect_uri must be the same as the url you have set for Canvas App. If you are using just Page Tab, the redirect_uri can be anything.
$loginUrl = $facebook->getLoginUrl(array(
"scope" => "email,user_education_history,user_work_history",
"redirect_uri" => "http://mydomain.com/login/facebook",
));
Im creating a mobile website and trying to implement facebook connect. I am using the PHP SDK
I have following code:
$loginUrl = $facebook->getLoginUrl(array(
'auth_token' => $session['auth_token'],
'next' => 'http://www.site.com/fbconnect',
'cancel' => 'http://www.site.com/fbconnect',
'canvas' => 0,
'fbconnect' => 1,
'req_perms' => 'publish_stream'));
I sign in, but I never get redirected back to my app. I stay on m.facebook.com w/ a msg
The page you requested was not found.
Is there something im missing?
Your site details under the "website" section of your app need to point to the same directory as you call from, that is the most common issue for failure to callback to your site. Assuming the "next" is the URL you wish the user to return to of course.