I am trying to get app_data from the facebook canvas.
It's working in page tab.
https://www.facebook.com/something/app_55218516481307?app_data=4B9E753
$signed_request = $facebook->getSignedRequest();
$app_data = $signed_request["app_data"];
app_data contains the value - '4B9E753' So, it's nice.
But there, app_data is not even set.
https://apps.facebook.com/namespace/?app_data=something
signed_request contains only
Array (
[algorithm] => HMAC-SHA256
[issued_at] => 65456446
[user] => Array (
[country] => cz
[locale] => cs_CZ
[age] => Array (
[min] => 21
)
)
)
Why?
It only works in a page tab and not on the canvas page.
https://developers.facebook.com/docs/reference/login/signed-request/
to send data to the app on its canvas app page use
'https://apps.facebook.com/yourappname?sk=app_yourapp_id/whatever_you_wish_to_send/'
and get it in php with $thisrequest = $_REQUEST['sk']; you can echo it to see what you get back.
Related
I developped months ago a page to automatically post on my 2 Facebook pages. I could post just a message but also add a link and/or a picture.
Everything worked like a charm and my latest post was succesfull the 25th of Nov.
Today, I try to publish a news with just a picture and I received an error 100# message which says : "A link must be provided if a picture URL is given".
I can't find any explaination nor help on this subject. It seems that Facebook changes its rules concerning the publication of pictures.
Basically here is the error dump :
FacebookApiException Object
(
[result:protected] => Array
(
[error] => Array
(
[message] => (#100) A link must be provided if a picture URL is given.
[type] => OAuthException
[code] => 100
[fbtrace_id] => xxxxxxxxxxxx
)
)
[message:protected] => (#100) A link must be provided if a picture URL is given.
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /mypathtofacebook/base_facebook.php
[line:protected] => 1042
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /mypathtofacebook/base_facebook.php
[line] => 747
[function] => throwAPIException
[class] => BaseFacebook
[type] => ->
[args] => Array
(
[0] => Array
(
[error] => Array
(
[message] => (#100) A link must be provided if a picture URL is given.
[type] => OAuthException
[code] => 100
[fbtrace_id] => xxxxxxxxxxxxxxxxx
)
)
)
)
[1] => Array
(
[function] => _graph
[class] => BaseFacebook
[type] => ->
[args] => Array
(
[0] => /mypageid/feed
[1] => post
[2] => Array
(
[access_token] => myaccesstoken
[from] => myAPPid
[message] => blabla
[picture] => http://www......................jpg
[to] => mypageid
The only thing that changed is that I had to change my FB password. So my access_token was no longer valid and I generated a new one.
I used the same process to get this new access_token and I can post on Pages. But once again, only text and link, but no picture alone anymore.
Another info: I try to repost the same picture that the one posted the 25th of Nov and I have the error. So it's definitely not an error in the picture URL or in the image itself.
Thanks in advance
https://developers.facebook.com/docs/graph-api/reference/v2.5/page/feed#publish
Posting a picture requires a link - the picture is actually the "preview image associated with the link". You can also post to the /page-id/photos endpoint if you want to post a picture without a link.
I solved the problem for myself - do not choose the entry from the menu; instead type {{product.url}} yourself.
This is not your fault, Facebook changed something regarding to the posts.
This happened to me as well .. I was in the same situation as you were .. had a working script for months, and all of a sudden publishing posts without links didn't work anymore.
I could not find any other solution than to post the picture with a link ...
SOLUTION: Until now, if no link was specified, Facebook would of used the actual image src as the link, so what you can do is add that specific link in your posting tool if no actual link is specified
I know this is old but in addition to the endpoint mentioned by the accepted answer /page-id/photos you need to set the source with the fileToUpload method: https://developers.facebook.com/docs/php/FacebookFile/5.0.0
I have a page tab app. When the user clicks on the "Go to App" and is sent to my page tab edit url i am trying to determine if they are a page admin or not.
I have tried two different methods. I have tried from the only admin/owner of the page
method 1 used from https://developers.facebook.com/blog/post/2011/09/05/platform-updates--labor-day-edition/
$page_info = $facebook->api("/".$pageID."?fields=access_token");
$pageAccessToken = $page_info['access_token']
$is_admin_url = "https://graph.facebook.com/" . $pageID
. "/admins/" . $FBuser . "?access_token="
. $pageAccessToken;
$response = file_get_contents($is_admin_url);
response is {"data":[]}
I have also tried::
path = '/'.$pageID.'/admins/'.$FBuser;
$params = array(
'app_id' => FB_APP_ID,
'access_token' => $pageAccessToken
);
$is_admin = $facebook->api($path, 'POST', $params);
Although PAGE_ID/admins is a valid request, you need an admin's access_token to see the list. I.e. only admins can see who else is an admin.
What you can do is approach this from the other end by yielding a list of pages that the user is an admin of (using the https://graph.facebook.com/USER_ID/accounts/ data and the manage_pages permission) and search through that list for your application.
However, I would understand if some users would be reluctant to give the manage_pages permission, as it also provides an access token to authenticate as that page, which would be something of a security hole on their part. Unfortunately, there does not seem to be another way to access a list of pages for which that user is an admin.
Simplest way will be signed Request.
A signed_request parameter is POSTed to an application when the app is loaded inside a Page Tab.
You can get a lot of information from signed_request
require '../fb_sdk/facebook.php';
$config = array();
$config['appId'] = '45916xxxxxx';
$config['secret'] = '59caxxxxxx';
$facebook = new Facebook($config);
$facebook->setFileUploadSupport(true);
$signed_request = $facebook->getSignedRequest();
print_($signed_request); will have output like
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1347210000
[issued_at] => 1347203265
[oauth_token] => AAAGhmv67ki8BAAfBwtxxxx
[page] => Array
(
[id] => 192430xxxxxx
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => in
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
[user_id] => 10000020xxxxx
)
You can use $signed_request[page][admin] value to determine whether a user is admin of current page, in which your app in loaded in Page Tab. If it's set to 1 then user is admin of the page else not an admin i.e. set to 0.
More About Signed Request
i had some luck using admin_only = true
https://developers.facebook.com/docs/graph-api/reference/user/groups/
Is there anyway to get the state information of the user visiting my facebook tab page? Currently via signed request i can get the country information. Is there a way to get state information also??
Answer is NO, check out the documentation here https://developers.facebook.com/docs/authentication/signed_request/
You get data like this
Array (
[algorithm] => HMAC-SHA256
[issued_at] => 1328803958
[page] => Array (
[id] => 114951721840
[liked] => 1
[admin] => 1 )
[user] => Array (
[country] => us
[locale] => en_US
[age] => Array ( [min] => 21 )
)
)
I'm trying to get a the facebook userid in a facebook tab, but somehow this always returns 0.
This is the code I use:
$config = array();
$config["appId"] = "427761887242287";
$config["secret"] = "xxxxxxxxxxxxxxxxxxxxxx";
$facebook = new Facebook($config);
$fbData = $facebook->getSignedRequest();
Facebook appId and secret are valid, I've already tried with resetting the secret.
I've tried to do a print_r on $fbdata but this only returns:
Array
(
[algorithm] => HMAC-SHA256
[issued_at] => 1337603346
[page] => Array
(
[id] => 158282080958121
[liked] => 1
[admin] =>
)
[user] => Array
(
[country] => nl
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
)
As you can see, this retuns only some non usefull data as far as the user goes.
I've also tried $facebook->getUser() but this does return 0.
I do have a valid SSL certificate on my server, I use the right http and https URL's but I can't find out why I get a 0 for the userid while I'm logged in.
Any suggestions?
If this is a facebook page tab application, then the user id is not returned unless the user has explicitly authorized your application. And from the response you've posted it looks like this is the case. You would need to get the user to authorize your application, not just like a page for this to work
https://developers.facebook.com/docs/authentication/pagetab/
Is it possible to programmatically add an event to a page using Facebook Graph API?
If yes, what HTTP request shall be made?
For example, Startup Weekend has events on its Facebook page.
These events can be added using Graph API Event object?
UPDATE
Creating event with the API is no longer possible in v2.0+. Check: https://developers.facebook.com/docs/apps/changelog#v2_0
Yes it's possible.
Permissions:
create_event
manage_pages
So first you get the page id and its access token, through:
$facebook->api("/me/accounts");
The Result will be something like:
Array
(
[data] => Array
(
[0] => Array
(
[name] => Page Name
[category] => Website
[id] => XXXXXX
[access_token] => XXXXX
)
[1] => Array
(
[name] => Page Name 2
[category] => Company
[id] => XXXXXXX
[access_token] => XXXXXXXX
)
)
)
UPDATE: To retrieve the page's access_token you could now call the page object directly like:
$page_info = $facebook->api("/PAGE_ID?fields=access_token");
The access token, if successful call, should be accessible: $page_info['access_token']
Now you get the Page ID and access token and use the events connection:
$nextWeek = time() + (7 * 24 * 60 * 60);
$event_param = array(
"access_token" => "XXXXXXXX",
"name" => "My Page Event",
"start_time" => $nextWeek,
"location" => "Beirut"
);
$event_id = $facebook->api("/PAGE_ID/events", "POST", $event_param);
And you are done! :-)