Facebook Profile Pic API - get someone's full photo - facebook

I know how to get someone's thumbnail via the Facebook API, but how do you get the person's full profile pic? What permissions are necessary to do this?

Append type=large to the query string. For example https://graph.facebook.com/100/picture?type=large

The full profile picture can not be retrieved via the user's picture connection (https://UID/picture?type=large will only return a picture of about 200x200).
To get the largest version of the profile picture stored on Facebook, you need to access the user's profile photo album. This requires user_photos permission.
The full profile picture can be retrieved by iterating over the albums, looking for the album which has the the type 'profile' and then getting its cover page:
public function getProfilePictureMaxUrl($facebook,$uid,$userAccessToken) {
$params = array('access_token' => $userAccessToken);
$r = $facebook->api('/'.$uid.'/albums',$params);
foreach ($r['data'] as $album) {
if ($album['type'] == 'profile') {
//retrieve information about this album
$r = $facebook->api('/'.$album['id'],$params);
$pid = ($r['cover_photo']);
//retrieve information about this photo
$r = $facebook->api('/'.$pid,$params);
return $r['source'];
}
}
//Profile folder not found (could be because of paging)
error_log('Failed to retrieve profile folder for uid '.$uid);
return false;
}

Related

Get public photos from facebook using xamarin.Social

Can anyone help me to get public photos from a Facebook page. I'm developing a mobile app using Xamarin.Forms in which I need to get public photos from Facebook.
Currently I'm using Xamarin.Social to integrate Facebook in the app and I'm able to login into a Facebook account but not able to get public photos.
Use the Xamarin.Auth to query the relative facebook API link. For Example, to get the user name and ID you can use:
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/v2.4/me"), null, _currentUser);
await request.GetResponseAsync().ContinueWith(t =>
{
if (t.IsFaulted)
return;
else
{
string mail = t.Result.GetResponseText();
Dictionary values =
JsonConvert.DeserializeObject>(mail);
bool s = values.TryGetValue("name", out _name);
bool i = values.TryGetValue("id", out _userId);
if(!s){
_name = "Error Getting Username";
}
if(!i){
_userId = "Error Getting Id";
}
}
});
To explore the Facebook API you can follow this link
Hope this helps.

Facebook C# SDK and Web API - (OAuthException - #120) (#120) Invalid album id

I have a client app that authenticates to Facebook and then furnishes the access token to Web API methods that are using the Facebook C# SDK, such as posting to the user's photo album:
var facebook = new FacebookClient(photoDTO.FacebookSessionToken);
dynamic result = facebook.Post("me/photos",
new
{
message = photoDTO.Photo.Comments,
file = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = fileName,
}.SetValue(imageBytes)
});
This code used to work, however now I am getting an exception: "(OAuthException - #120) (#120) Invalid album id". I believe that this error has something to do with the authentication token, but I've checked that the token is valid by browsing to https://graph.facebook.com/me?access_token=... and it does correctly return the profile of the user currently logged into the app. I am using SDK version 6.0.10.0.
How can I post to the currently logged in user's profile using the authentication token passed from the client app?
Not sure if this an answer or just a workaround but since I knew the name of the album I wanted to post to, I queried the user's albums to get the album id and then used that to post directly to the album:
var facebook = new FacebookClient(photoDTO.FacebookSessionToken);
string albumId = null;
string albumName = "Album";
dynamic albums = facebook.Get("me/albums");
// Get the album id of the album we want to post to
foreach(dynamic albumInfo in albums.data)
{
if (albumInfo.name == albumName)
{
albumId = albumInfo.id;
break;
}
}
// If album does not exist, create it
if (albumId == null)
{
dynamic album = facebook.Post("me/albums",
new
{
name = albumName
});
albumId = album.id;
}
// Post the photo to the album
dynamic photo = facebook.Post("/" + albumId + "/photos",
new
{
message = photoDTO.Photo.Comments,
file = new FacebookMediaObject
{
ContentType = "image/jpeg",
FileName = fileName,
}.SetValue(imageBytes)
});
Please note that Album ID is different from Album name , this is your issue you are comparing album ID to album Name ! check the album api here
the proper algorithm is to :
find album ID , if it is there , then post the media to specified ID , else handle the error
FB.api(
"/{album-id}",
function (response) {
if (response && !response.error) {
//album was found , your code goes right here.
}
else {
//album was not found handle your error.
}
}
);

how to retrieve the id of the album profile facebook

I seek how to retrieve the id of the profile album facebook
I found this code
$albums = $facebook->api("/me/albums");
foreach($albums["data"] as $item){
echo $item["type"]." *********** ".$item["id"]."<br />";
/if($item["type"] == "profile"){
$album_id = $item["id"];
break;
}
}
but unfortunately he only shows 25 album and if the user has more than 25 album you can not recover its id of the profile photo abum
thank you very much
Try setting the limit parameter to a higher value – $facebook->api("/me/albums?limit=500");
And if that doesn’t help, there should be prev/next-URLs in the response your getting, so you have to follow those.

Post on Friends' Wall(s) via Facebook Actionscript 3 SDK

I'm absolutely new to programming and just managed to learn the basics of ActionScript 3. Now, I would like to learn how to post on my Friends' Walls via the as3 SDK using the UI class (taken from a nice Tutorial):
This is how I post on my own Wall:
protected function newsFeed ():void
{
// define your caption text
var theCaption:String = "CaptionText";
// define the descrition text
var theDescription:String = "Text for game Achievement";
// We need to follow the FB docs to tell it what sort of input we are sending to FB
// We are trying to set the 'feed'
var methodInput:String = 'feed';
var thePicture:String = "mylink/picture.png";
var theLink:String = "mylink";
var theName:String = "Name of FB Status Setter";
// Create an object that we'll call 'data' and fill it with the actual data we're sending to Facebook
var data:Object = {
caption:theCaption,
description:theDescription,
picture:thePicture,
name:theName,
link:theLink
};
Facebook.ui(methodInput, data, onUICallback);
}
protected function onUICallback(result:Object):void
{
// do something
}
This works perfectly fine. I know that I have to integrate the parameter "to" somewhere. But I don't know where and how. Sorry I'm very very new to this. This is from Facebook Docs
Properties
from: The ID or username of the user posting the message. If this is unspecified, it defaults to the current user. If specified, it must be the ID of the user or of a page >that the user administers.
to: The ID or username of the profile that this story will be published to. If this >is unspecified, it defaults to the the value of from.
Hopefully someone can help me out.
Best Regards,
Amir
P.S.: Is there a way to post only one friend's wall and another way to post on several friends' walls?
I believe you want to use Facebook.api() rather than 'ui'. According to the documentation for the AS3 FB API, 'ui' just opens the share dialog. If you want to create a post on a friends wall, then you'll want to use 'api'.
I haven't tested this in Flash, but I think you can set the method as /PROFILE_ID/feed ... of course replacing "PROFILE_ID" with the FB uid of the friend. Then, include the arguments; message, picture, link, name, caption, description and source in your data object.
So your code would look something like:
var method:String = "/friend_id/feed";
var data:Object = {};
data.message = "Your message";
data.picture = "http://www.google.com/kittens.jpg";
data.link = "http://www.mysite.com/link";
data.caption = "Your caption";
data.description = "Your description";
data.source = "http://www.mysite.com/video.swf";//(optional) source is a video or Flash SWF
Facebook.api(method, yourCallback, data, "POST");
function yourCallback(result:Object, fail:Object):void {
if (result) {
trace(result)
} else if (fail) {
trace(fail);
}
}
If you have multiple friends, you could probably just put the uid's in an array and loop through the method above. The AS3 API has a batch request method that I haven't tried, but you can check out the Documentation.
Facebook has some pretty helpful tools that are somewhat hidden.
Checkout their Debugger and their Graph API Explorer
Hope that's helpful.

facebook post users wall

i have a#yahoo.com account and also created facebook account
another two users have also facebook account by b#yahoo.com and c#yahoo.com per each.
b#yahoo.com and c#yahoo.com account holder pressed like button of the fan page owned by
a#yahoo.com holder.
now as a fan page [a#yahoo.com] but not as others, I like to post some
message,attachment [to the wall of
the selected users + users who liked fan page] among all of the users.
now I select only b#yahoo.com user.
the code is given below:
I accepted manage_pages,offline_access,publish_stream permission.
$page_id = "YYYYYYYYYYYYYYYY";
$page_access_token = "";
$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
if($page["id"] == $page_id) {
$page_access_token = $page["access_token"];
break;
}
}
$data["access_token"] = $page_access_token;
$data["message"] = "aaaaaaaaaaaaaaaaa";
$data["name"] = "ttttttttttttt";
$data["caption"] = "cccccccccccccc";
$data["link"] = "http://www.facebook.com/pages/CCCCC/OOOOOsk=app_UUUUUUUUUUU";
$data["description"] = "aaaaaaaasdfsfsdf";
$data["picture"] = "http://cdn1.kingdomsofcamelot.com/fb/e2/src/img/fte/army_troop.png";
$post_id = $facebook->api("/$page_id/feed", "post", $data);
but the above code post the message,attachment to the wall of all users who liked
the fan page,but I only write post to the specific users.
how can I achieve? or is there any possiblity to pass the target users id only?
I'm not entirely sure i understood your problem.
Your code posts a post to the fan-page wall - not to the "wall of all users who liked the fan page".
As a fan page, you can not write to a user's wall, even if he is a fan of your fan-page.