Facebook::Graph for number of likes - facebook

Can I use Facebook::Graph to retrieve the number of likes without dealing with authorization tokens? The following code:
use Facebook::Graph;
my $fb = Facebook::Graph->new;
my $hashref = $fb->query
->request('https://graph.facebook.com/btaylor')
->as_hashref;
produces the following error:
Unable to create sub named ""
I'm not a real perl coder so I may be way off.
http://search.cpan.org/~rizen/Facebook-Graph-1.0501/lib/Facebook/Graph.pm

You can. Your problem is that btaylor is a regular facebook user and users cannot be liked. For objects that can be liked you can query for a list of likes following the example below.
https://graph.facebook.com/thagroggs

Related

simple perl assistance using hash values

I'm very new to perl and am working with facebook authentication. This is the cpan facebook library
In it, during the callback i have the following code:
my $info = $fb->get(
'https://graph.facebook.com/v3.1/me?fields=birthday,email,name,id' # Facebook API URL
);
This is the response from $info->as_json;
{"email":"someemail\u0040email.com","name":"some user","id":"fbid"}
I've tried accessing the values using $info->email and $info->{email} and $info->{'email'} into my debugger but im getting null values. How do i obtain these values from the $info variable (hash?)
According to the documentation to which you linked, the proper usage is
my $data = $response>as_hash;
$data->{email}

I can not get the number of followers on a page

I'm trying to get the number of followers on a page. That is, obtain the number that appears in the portal as: "1363 people follow this"
I am trying to make the call as follows:
Dim urlSocialAnalitics As String =
String.Format ("https://graph.facebook.com/{0}/friends?summary=total_count&access_token={1}", pIdFanPage, pToken)
But it does not work. It's a problem for me.
I have also tried with this url:
urlSocialAnalitics = String.Format("graph.facebook.com/v2.6/{0}?fields=fan_count&access_token={1}", pIdFanPage, pToken)
But this gives me the number of Likes and not of Followers
I have read the documentation:
https://developers.facebook.com/docs/graph-api/reference/page/
But I do not see anything about it.
What is the correct call?

Issue retrieving friendlists from Facebook through Koala gem

I am working with a project started by someone else which interacts with Facebook through the Koala gem. For some odd reason it will allow me to create friend lists but when I retrieve them I get nothing. I can verify I have friend lists available through the Graph API by using Facebook's Graph API Explorer tool, and I do have the "manage_friendlists" permission in the application. I can also verify that it successfully adds friend lists through this application and trying to add an identically named friend list will return an error (which it should). However, when it gets to the point of actually retrieving them through the app, it simply returns the hash
{:me => {:id => 'my_id'}}
with nothing else. The method is written as
def friendlists
graph_api.get_objects('me', {fields: 'friendlists'})['me']['friendlists']['data']
end
which gives an 'undefined method [] for nilClass' since there is no 'friendlists' nested hash returning. I am using Koala 1.4.0 if that makes any difference. Any thoughts or suggestions? Thanks!
I am also using koala gem... you can use it as follows:
session['fb_access_token'] is the one when user is logging in, I am assigning as follow:
session['fb_access_token'] = auth['credentials']['token']
def self.fetching_facebook_friends
#graph = Koala::Facebook::API.new(session['fb_access_token'])
profile = #graph.get_object("me")
#profile_image = graph.get_picture("me")
friends = #graph.get_connections("me", "friends?fields=id, name, picture.type(large)")
end

facebook graph api check if user is a member of a group using PHP

i want to check if a user is a member of a group using facebook graph api...
i have this:
$group = file_get_contents("https://graph.facebook.com/177129325652421/members?access_token=XXXXXXXX");
$group = json_decode($group);
$checkuser = $group->data;
and check the user if is a member by using his facebook id and in_array()
if(in_array($_GET["fid"],$checkuser)){
echo "yes";
} else {
echo "no";
}
can someone help me to correct this please... my code is not working...
Reference: https://developers.facebook.com/docs/reference/api/
Use the API url:
https://graph.facebook.com/me/groups
To get a user's groups. In the above link, change the me/ to the user's FB ID. You must also pass in an Access Token.
The reply will be JSON encoded. Decode it using json_decode to a PHP Associative array. Iterate over it and check for the group you want.
The Graph API does not return all groups at once. You must either use the pagination links at the end of each response to fetch more, or use the limit parameter to request as many as you need.
The following code sample will post the IDs of the Groups you are a part of
<?php
$url = "https://graph.facebook.com/me/groups?access_token=AAAAAAITEghMBAMDc6iLFRSlVZCoWR0W3xVpEl1v7ZAxJRI3nh6X2GH0ZBDlrNMxupHXWfW5Tdy0jsrITfwnyfMhv2pNgXsVKkhHRoZC6dAZDZD";
$response = file_get_contents($url);
$obj = json_decode($response);
foreach($obj->data as $value) {
echo $value->id;
echo '<br>';
}
/* to check for existence of a particular group
foreach($obj->data as $value) {
if ($value->id == $yourID) {
//found
break;
}
//not found. fetch next page of groups
}
*/
PS - If running the above code gives you an error stating Could not find wrapper for "https", you need to uncomment/add the PHP extension extension=php_openssl.dll
Was looking into this and found this as first answer in google but the answer seems to be much of a hassle so I dug a bit deeper.
The fastest answer I've found which doesn't require iterating through all of the groups' members uses FQL.
SELECT gid, uid FROM group_member WHERE uid = (user id) AND gid = (group id)
This either returns an empty 'data' object, or a 'data' object with the UID and GID.
It also (from what I see so far) , doesn't require the user_groups permission.
https://developers.facebook.com/tools/explorer?fql=SELECT%20gid%2C%20uid%20FROM%20group_member%20WHERE%20uid%20%3D%20551549780%20AND%20gid%20%3D%20282374058542158
This FQL query returns for me:
{
"data": [
{
"gid": "282374058542158",
"uid": "551549780"
}
]
}
This doesn't seem to be possible after Graph API v2.4, because Facebook decided to disallow it:
https://developers.facebook.com/docs/apps/changelog#v2_4
"the user_groups permission has been deprecated. Developers may continue to use the user_managed_groups permission to access the groups a person is the administrator of. This information is still accessed via the /v2.4/{user_id}/groups edge which is still available in v2.4."
It also states "From October 6, 2015 onwards, in all previous API versions, these endpoints will return empty arrays." But it seems to me that it still works on v2.2 & v2.3.

I am having problems running Facebook FQL queries that include long user ids

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.