I'm using the Facebook SDK and we created an app which worked just as we needed. We could $FacebookSDK->getSignedRequest() in PHP and it would respond with an object that included pages->liked which allowed us to determine if the user likes the page or not.
Anyway, we have created an exact duplicate application (the only difference being that this app is about 3 months newer than the old) and the like property has completely disappeared and I can't get my hands on it.
Any ideas why this is happening - has Facebook restricted their SDK yet further and removed this property for new apps?
Example Before:
stdClass Object
(
[algorithm] => HMAC-SHA256
[issued_at] => 1408626697
[page] => stdClass Object
(
[id] => ************
[admin] => 1
[liked] => 1
)
[user] => stdClass Object
(
[country] => gb
[locale] => en_GB
[age] => stdClass Object
(
[min] => 21
)
)
)
Example After:
stdClass Object
(
[algorithm] => HMAC-SHA256
[issued_at] => 1408625335
[page] => stdClass Object
(
[id] => ************
[admin] => 1
)
[user] => stdClass Object
(
[country] => gb
[locale] => en_GB
[age] => stdClass Object
(
[min] => 21
)
)
)
Notice that the only thing missing here is the likes property so I can't tell if the user likes our page tab or not! Facebook is doing my nut in to develop on these days!
Thanks,
Chris.
https://developers.facebook.com/docs/apps/changelog
(see v2.1 changes)
Fan-/Like-Gates are not possible anymore, and not allowed according to the Platform Policy. Old Apps will always return "true" in the signed_request parameter after 5th of November 2014.
Related
I am trying to fetch data from user's twitter account with this code
$user_info = $twitteroauth->get('account/verify_credentials');
i get a very long value in an object
stdClass Object
(
[id] => 2999359418
[id_str] => 2999359418
[name] => ABC
[screen_name] => ABC9
[location] =>
[profile_location] =>
[description] => XYZ
[url] =>
[entities] => stdClass Object
(
[description] => stdClass Object
(
[urls] => Array
(
)
)
)
[protected] =>
[followers_count] => 0
[friends_count] => 0
[listed_count] => 0
[created_at] => Wed Jan 28 12:17:43 +0000 2015
)
i wish to retrieve data from it.
eg. i tried to retrieve description by this code but did it wrong, coz i did not get the result. can anyone please tell how to fetch the data
The information is not an array, but an object. You can access the data by the following:
$info = $user_info->description;
You can repeat this by to go further down the chain such as:
$user_info->entities->description, etc.
You are trying to access a object with the array index syntax it will not work this way.
When you are dealing with objects you need to access the array by using "->"
$user_info->name;
$user_info->entities->description;
$user_info->entities->description->urls;
This is the pattern to access to the depth
so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }
I have a facebook application and a tab page which links http://localhost/a/index.php, I have successfully add this tab page to my pages. I wrote in index.php
$checkLoggedIn = $facebook->getSignedRequest();
it return me like this
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1324648800
[issued_at] => 1324644411
[oauth_token] => AAACMkfuFjmIBAEJ9zqtJVvDK08aXlO1wSEFVNvekyCWcZBtnQcJ8BTCYfwZBMyrom5nazjPCsF56v4hLCBi2VywUzgrLSTYr9sbMmTWDN5QFFeOBfU
[page] => Array
(
[id] => 309081639123289
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => bd
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
[user_id] => 1549070809
)
its ok for me. I have also another link on that page is start.php with same code but it return to me like this
Array
(
[algorithm] => HMAC-SHA256
[code] => 2.AQAHgyMnInvOgkoU.3600.1324648800.5-1549070809|OMFOQPTFesejPmg0h2SfwwNGGEY
[issued_at] => 1324644436
[user_id] => 1549070809
)
what can I now? to get same object. because they are in same iframe.
This is because the facebook sdk only saves some information in the session (your second array). To remember the page, you have to manually save it.
A few days ago I released a beta version of a game on Facebook.
Unfortunately, I'm not so lucky, and in the first most important days of the application when users first use it, they keep getting errors resulting from errors on my PHP Apache server which gets the following errors from Facebook API -
couldn't connect to host
connect() timed out!
My server runs on a free server I got from Joyent for facebook developers.
I'm not a big expert with web servers so I got no idea if the problems are from my side or Facebook side.
And how can I fix this problem quickly!
Thanks a lot!
Edit:
For some reason I forgot about the code samples and error examples -
Here's an example for a simple query against facebook -
$session = $facebook->getSession();
$currentID = $facebook->api('/me?fields=id');
Here's the error stack trace -
couldn't connect to host StackTrace: Array
(
[0] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 523
[function] => makeRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
)
)
)
[1] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 491
[function] => _oauthRequest
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => https://graph.facebook.com/me?fields=id
[1] => Array
(
[method] => GET
)
)
)
[2] => Array
(
[function] => _graph
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
[3] => Array
(
[file] => /users/home/aagnt2sv/web/public/Facebook/facebook-php-sdk-7d538d3/src/facebook.php
[line] => 444
[function] => call_user_func_array
[args] => Array
(
[0] => Array
(
[0] => Facebook Object
(
[appId:protected] => *censored*
[apiSecret:protected] => *censored*
[session:protected] => Array
(
[uid] => *censored*
[access_token] => 104269778819|2.AQAKqpIXE0jqFuoU.3600.1311008400.1-785849095|qxtBqmWWRMc_GpM77CK77RbO4YA
[expires] => 1311008400
[sig] => ddf14dcaa953cb64d3f98b0649b60613
)
[signedRequest:protected] =>
[sessionLoaded:protected] => 1
[cookieSupport:protected] => 1
[baseDomain:protected] =>
)
[1] => _graph
)
[1] => Array
(
[0] => /me?fields=id
)
)
)
[4] => Array
(
[file] => /users/home/aagnt2sv/web/public/edamometer/EdamometerWS.php
[line] => 31
[function] => api
[class] => Facebook
[type] => ->
[args] => Array
(
[0] => /me?fields=id
)
)
Thanks again!
This was somehow fixed by itself after several days. Maybe it was a temporary problem on my server or on Facebook's servers.
Get user id with
$fb = new Facebook(array(
'appId' => 'your_app_id',
'secret' => 'your_app_secret',
));
$user = $fb->getUser();// returns user id
I'm currently having this problem with my server (using PHP to access the Facebook API), as well. Based upon the nature of the error message, obviously the problem is the connection between my server (running on the Amazon cloud, btw) and Facebook's server(s).
What is throwing me for a loop, though, is that some commands are working properly. That is, attempting to log in with one Facebook token is working fine, while another in causing this error message.
The only reasonable explanation I can come up with is that the Facebook servers are experiencing some sort of temporary hiccup... but even that does a poor job of explaining the problem, since it is somehow tied to the token which is being used. The only way it makes sense is if there's some sort of bug where Facebook's servers are timing out in processing the specific token I'm giving them...
Take the following JSON string (generated by some ExtJS code - but that's irrelevant):
[{"action":"Setting","method":"toggle","data":["welcome-home"],"type":"rpc","tid":2},{"action":"ContentExtFeFillout","method":"todo","data":[true,0,8,false],"type":"rpc","tid":3}]
being sent to a server as a POST request and retrieved via $GLOBALS['HTTP_RAW_POST_DATA'].
Running
json_decode($GLOBALS['HTTP_RAW_POST_DATA']);
on our development machine (5.2.10-2ubuntu6.4 with Suhosin Patch 0.9.7) gives a correct print_r() output of:
Array
(
[0] => stdClass Object
(
[action] => Setting
[method] => toggle
[data] => Array
(
[0] => welcome-home
)
[type] => rpc
[tid] => 2
)
[1] => stdClass Object
(
[action] => ContentExtFeFillout
[method] => todo
[data] => Array
(
[0] => 1
[1] => 0
[2] => 8
[3] =>
)
[type] => rpc
[tid] => 3
)
)
Running the same code on a client's production machine (5.2.5 with Suhosin Patch 0.9.6.2 and Zend Optimizer; SUSE Linux by the way) gives the following print_r() output:
Array
(
[0] => stdClass Object
(
[action] => Setting
[method] => toggle
[data] => Array
(
[0] => welcome-home
)
[type] => rpc
)
[1] => 2
[2] => stdClass Object
(
[action] => ContentExtFeFillout
[method] => todo
[data] => Array
(
[0] => 1
[1] => 0
[2] => 8
[3] =>
)
[type] => rpc
)
[3] => 3
)
Note the missing tid property which obviously has been moved into the main array as an own value - this naturally breaks all the following code.
We also downloaded a Windows PHP version 5.2.5 to check if there's a bug in json_decode() but we get the correct output here.
Are there any known issues with json_decode() at all that could cause this odd behavior?
We're currently totally clueless...
Thanks to all of you!
Best regards
Stefan
OK guys - problem solved. Lacking any more options we persuaded the client to update the installed PHP version and guess what: it works.
There seems to have been a subtle bug in their PHP installation (PHP, Zend Optimizer and/or Suhosin) which has been fixed with the update. Still, a quite weird thing.
Thanks to all of you!
Best regards
Stefan
Have you tried swapping the tid and type keys? Also how about using a hardcoded variable to check if the problem could be with $GLOBALS['HTTP_RAW_POST_DATA']?
Try the following:
$t1='[{"action":"Setting","method":"toggle","data":["welcome-home"],"type":"rpc","tid":2},{"action":"ContentExtFeFillout","method":"todo","data":[true,0,8,false],"tid":2,"type":"rpc"}]';
print_r(json_decode($t1));