How to fetch Facebook profile picture & name w/o app? - facebook

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.

Related

How to get Sharepoint user by Title using REST?

I'm trying to search for a given user on a Sharepoint site using "lastname, firstname". I was able to use the following url to get the total list of site users as a large XML document:
https://thissite.com/sites/thatsite/_api/web/siteusers/
However, I haven’t been able to figure out how to search by Title. When I use the following url:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbytitle(“lastname,%20firstname”)
I get this error:
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>
-1, Microsoft.SharePoint.Client.InvalidClientQueryException
</m:code>
<m:message xml:lang="en-US">
The expression "web/siteusers/getbytitle("lastname, firstname")" is not valid.
</m:message>
</m:error>
When I use the following url to get the same user's data:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbyid(41)
Then I successfully get XML returned with that user's data.
I guess I could just parse the list obtained from /siteusers and load it into a searchable data object, but I was hoping for something more direct.
UserCollection resource does not expose getbytitle method, that's the reason why you get this exception.
In order filter user by title you could utilize $filter query option as demonstrated below:
https://contoso.sharepoint.com/_api/web/siteusers?$filter=Title eq '<Title>'

Facebook graph api returns empty result

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}

Retrieve User ID of Facebook App Invitor

In the context of a given Facebook app, suppose User A invited user B to start using it. Once User B accepts to use the app, is there any way to retrieve the ID of User A programmatically (via either PHP/JS SDK) ? This doesn't seem quite documented.
For what it's worth, A/B users are friends, if it's any use.
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to get the corresponding request details like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$request_object = $facebook->api($request_id);
//this $request_object have sender facebook id in the field uid_from
}
If you look here:
http://developers.facebook.com/docs/reference/dialogs/requests/
You can see the object layout. Of note is the data property:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters.
In this object you can add your referring UserId and then when the request is claimed, you can then process it on your end.
Hope this helps.

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.

Dividing Facebook fullname and save as two arrays

I already use a MySQL database and want to combine with Facebook Connect. I did a fb:registration plugin and there I can get only the full name. How can I divide it into first name and surname and save those as two arrays?
You better use Graph API or FQL to get this info for your users if you want to be sure to get the correct first and last name in places...
With Graph API you can request info for multiple users like this:
GET http://graph.facebook.com/?ids={uid_1},{uid_2},{uid_n}&fields=first_name,last_name
There is some limits for number of users you can request info for (I'm not sure on the numbers, but 50 users works ok) and on URL length (which can be worked around issuing POST request and specifying method parameter equal to get to Graph API
Hope this helps :)
$name_arr = explode(' ',$name,2);
$first = $name_arr[0];
$last = isset($name_arr[1])?$name_arr[1]:'';
The first and last name are separated by the first space ' '.
Now excluding middle name :D
$name_arr = explode(' ',$name,3);
$first = $name_arr[0];
$last = isset($name_arr[1])?(isset($name_arr[2])?$name_arr[2]:$name_arr[1]):'';