I'm making FQL calls using the following url and then making a curl call.
$url = 'https://api.facebook.com/method/fql.query?access_token='.$access_token.'&query='.rawurlencode($query).'&format=JSON';
and I then pass the returned data through a json_decode call
I've got this query:
SELECT name,page_id,page_url FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid= $uid )
which returns a list of the names and pages for which the specified UID is an administrator.
On some PHP installs (and I've not been able to narrow it down) the page_id is turned from a long integer into a scientific notation - so 174311849258492 is returned as 1.7431184925849E 14 which of course breaks things.
As I can't reproduce this on my server I'm not sure where the conversion is happening. Digging around I've found a suggestion that doing this:
json_decode( preg_replace('/:(\d+,)/', ':"${1}",', $response ) );
will fix it
But why do some json_decodes cast into scientific notation for no apparent reason?
If you are using your own curl calls then you can simply append &format=JSON-STRINGS onto the end of the url which returns all items as strings.
As Danny pointed out its a 32/64 bit issue. FB assume that everything is 64 bit and pass back an integer for this value rather than a string.
So what you need to do is take the integers and convert them to strings BEFORE pulling them from the JSON array. Page IDs and Group IDs are passed as integers (Facebook user IDs are passed as strings)
The code to do this is:
$response = curl_exec($ch);
$err_no=curl_errno($ch);
curl_close($ch);
$response=preg_replace('/"gid":(\d+)/', '"gid":"$1"', $response );
$response=json_decode( preg_replace('/"page_id":(\d+)/', '"page_id":"$1"', $response ) );
if (isset($response->message)) {
throw new Exception ($response->message);
}
return( $response);
Related
I am trying to pull user feeds from facebook, But the array of result i am getting is empty. The code i am using is
$jsonurl = "https://graph.facebook.com/{$user_id}/feed?limit=25&access_token={$access_token}";
$json = file_get_contents($jsonurl,0,null,null);
$user_data = json_decode($json, true);
print_r($user_data);
The result always getting is
Array ( [data] => Array ( ) )
Can anyone help me to find what the issue is?
Thanks in advance
I have tried your give code in my php code.
It is working find. Please check that the USERID which you are posting has a feed.
To test try BMW, FACEBOOK userid so you can find the feeds.
Try below url you will get its feed.
https://graph.facebook.com/BMW/feed?limit=25&access_token={$access_token}
Does anyone have any idea how to fetch profile picture and first + last name of Facebook member by his profile link/ID without authorising app or anything.
You can retrieve that data from following URL:-
https://graph.facebook.com/USERNAMEORID?fields=id,name,first_name,last_name,picture
Replace "USERNAMEORID" to fb username or id of specified user.
You can fetch these data as following:-
<?php
$content = file_get_contents('https://graph.facebook.com/myid?fields=id,name,first_name,last_name,picture');
$content = json_decode($content, true);
print_r($content); // <- this print data as associative array, You can fetch it and get data
?>
I added a json_decode function to your code whereas the data coming form facebook graph is json format, So i used that function to convert json format to object, Then i used true parameter to make this object as associative array. Now you can fetch this array normally as any array.
If you need anything else tell me, I'll be happy to help.
I am having problems running queries with FQL that include a supplied "Large"(beginning with 10000..) User ID
here is an example of one that is not working:
fql?q=SELECT uid, first_name,last_name,pic,pic_square,name
FROM user
WHERE uid=100002445083370
Is there a way to encapsulate the long number so it's passed as a string?
here is another example:
/fql?q=SELECT src_big
FROM photo
WHERE aid IN (SELECT aid
FROM album
WHERE owner=100002445083370 AND type="profile")
ORDER BY created DESC LIMIT 1
Has anyone been able to solve this issue? I am testing the queries in the graph explorer with no luck as well.
I see what the problem is,
The User id I am trying to pass is supposed to be: "100002445083367", but from querying the list of friends and grabbing their User Id, I am getting back "uid":1.0000244508337e+14 which is being shortened to: 100002445083370 (php removing the e+14) throwing off the second query. I need to make sure the id I am grabbing is staying as a string value not a number while I pass it back and forth from PHP and Javascript.
The problem is because of the way PHP handles JSON_DECODE. I had to modify Facebook PHP SDK and add a preg_replace previous to the json_decode. It will make sure json_decode doesn't convert large integers to floats by first converting them to strings.
here is the code:
line 803 from base_facebook.php:
$result = json_decode(preg_replace('/("\w+"):(\d+)/', '\\1:"\\2"', $this->_oauthRequest($this->getUrl($domainKey, $path),$params)), true);
here is more information on the subject:
http://forum.developers.facebook.net/viewtopic.php?id=20846
What do you mean by "not working"?
That query works for me in Graph API explorer but the response is
{
"data": [
]
}
I think that user-id isn't valid; https://www.facebook.com/profile.php?id=100002445083370 gives a "Page not found" error for me.
we are using Perl and cpan Modul FeedPP to parse RSS Feeds.
The Perl script runs trough the different items of the RSS Feeds and save the link to the database, liket his:
my $response = $ua->get($url);
if ($response->is_success) {
my $feed = XML::FeedPP->new( $response->content, -type => 'string' );
foreach my $item ( $feed->get_item() ) {
my $link = $item->link();
[...]
$url contains the URL to an RSS Feed, like http://my.domain/RSS/feeds.xml
in this case, $item->link() will contain links to the RSS article, like http://my.domain/topic/myarticle.html
The Problem is, some webservers (which provides the RSS feeds) does an HTTP refer in order to add an session ID to the URL, like this: http://my.domain/RSS/feeds.xml;jsessionid=4C989B1DB91D706C3E46B6E30427D5CD.
The strange think is, that feedPP seams to add this session-ID to the link of every item. So $item->link() contain links to the RSS article, like http://my.domain/topic/myarticle.html;jsessionid=4C989B1DB91D706C3E46B6E30427D5CD
Even if the original link does not contain an session ID.
Is there a way to turn of that behavior of feedPP??
Thank you for any kind of help.
I took a look through http://metacpan.org/pod/XML::FeedPP but didn't see any way to turn have the link() method trim those session IDs for you. (I'm using XML::FeedPP in one of my scripts and the site I happen to be parsing doesn't use session IDs.)
So I think the answer is no, not currently. You could try contacting the author or filing a bug.
IMHO, the behavior is correct: uri components which follow a semi-colon are defined part of the path (configuration parameter for interpretation), so when the uri is used to make a relative url into an absolute uri it needs to be copied as well.
You expect compatible behavior with '&' parameters, but they are not equal.
https://rt.cpan.org/Ticket/Display.html?id=73895
im trying to get a param from my url.. via $this->_request->getParam('url')
so, /url/http://www.yahoo.com
but the value of param url is h because theres forward slashes in the value..
how can i get the full url... as now, its thinking that the http:// is another param..
public function getUrlToGo(){
$url=$this->_request->getParam('url');
if ($url='http://www.yahoo.com'){
return $this->_forward("findyahoo", "urlclass");
}
}
Usually when urls are passed in the address bar the slashes (and most other characters) are converted into url-safe characters.
<?php
$url = urlencode('http://www.yahoo.com');
echo $url; //http%3A%2F%2Fwww.yahoo.com
You can then use urldecode($url) to get the original url back.