When I upload a photo an album is automatically created. There's a way in which I could get the album ID from having the photo ID. Because I have this code:
try {
$response = $facebook->api(
'/me/photos/',
'post',
array(
'message' => 'This is my image caption',
'source' => $source
)
);
$id = $response['id'];
if ($id) {
//obtenemos la url del album
$response = $facebook->api('/'.$id);
unset($_SESSION['uploaded_file']);
header('Location: http://www.facebook.com/'.$id);
exit();
}
} catch ...
And I want to redirect the user to the albums (because I need the user to aprove the photos) instead of the photo. There's a way of doing this without actually asking for all user albums and checking where was the photo uploaded?
If I didn't oversee anything, there is no way to get the album id of the automatically created album.
As a workaround you can upfront create a new album for your application by using the albums connection of the User object. In the response you get the album id which you can use to upload photos specifically to this album and later redirect to it using the link attribute in the Album object.
You can get that info using FQL – first query the photos table for the aid of the album, and then query them album table with that:
SELECT object_id FROM album WHERE aid IN
(SELECT aid FROM photo WHERE object_id = "{your photo’s Graph API id}")
– the object_id will be the Graph API id of the album.
Related
I use FBRequestConnection to get photo's id and post id
But I want to know the photo's URL
How can I do ?
I did use [FBRequest requestForGraphPath:id] , but no URL return
Thanks for help
Usually url's of image posts returned with every graph object but if you want to get profile image
"http://graph.facebook.com/" + id + "/picture"
Where id can be profile id or user name .e.g.
http://graph.facebook.com/jansharkhan/picture
I want to upload picture to timeline of user or page.
I am able to upload picture to users wall but it has created new album with my application name. But i want to upload picture to timeline album of user.
I have uploaded picture using bellow code
var result = client.Post("/"+ id +"/photos", postparameters);
I solved it.I just filtered id of the album where I wanted to post picture & passed it in place if "id" of above code.
var result = client.Post("/"+ album_id +"/photos", postparameters);
you can get album id dynamic :
dynamic albums = app.Get("me/albums");
string AlbumId="";
foreach (dynamic albumInfo in albums.data)
{
if(albumInfo.name == "Timeline Photos"){AlbumId=albumInfo.id; break;}
}
and the you can use AlbumId to post in the album .
msm2020 solution do the trick but don't forget to add the albums permission: user_photos
I'm trying to get the user photos, but I cannot get the user's photos data.
I'm trying this:
$photos = $facebook->api('https://graph.facebook.com/'.$profileFID.'/photos?access_token='.$access_token);
print_r($photos);
I'm sure the URL is correct since pasting it in the browser shows the photos array. However when I try to print the array to check if I got it I get only this:
( [id] => https://graph.facebook.com/1409006586/photos )
How can I get the full array with the user photos?
The Facebook SDK will take care of constructing the url for you (and append the access_token), you just need to build the query:
$photos = $facebook->api('me/photos');
If the user is not currently logged in but you have the access_token, then use:
$photos = $facebook->api($profileFID.'/photos', 'get', array('access_token'=>$access_token));
P.S: always put your queries in a try...catch blocks
https://graph.facebook.com/1409006586/photos
replace photo by picture
ex
https://graph.facebook.com/4/picture
I have done a facebook application which upload photos into default application album. I found that after the upload, there will be a post displayed on user profile saying 'Smi added 10 new photos to the album xxxxx.'. Is it possible to edit the message above to 'Smi added 1 new photo to the album via xxxapplication'? I am using Graph api to upload the photo. The code I am using to upload is
$file = "#".realpath($image);
$args = array(
'message' => '',
"access_token" => $access_token,
"image" => $file
);
$data = $facebook->api('/me/photos', 'post', $args);
No you have no control over the activity feed message for items like that. The only items you will be able to control when uploading are photo captions, album titles, and tagged users.
I use Graph API and I need to get users' profiles pictures by their UIDs.
It's easy to do: http://graph.facebook.com/[Facebook UID]/picture
I remember, some time ago, there was a litte Facebook Logo (litter 'f'-char) on these profile pictures. But now, I get only profile pictures without this logo.
How can I get images with this 'f'-logo?
Facebook doesn't store images with the 'f' on, so it's a little hacky to get at them.
I've found that this works:
You'll need the final image url, after graph.facebook.com/[id]/picture redirects.
http://external.ak.fbcdn.net/safe_image.php?&url=[imageurl]&logo
eg. me
I think it's not possible using the graph api.
It was possible using FQL (dont know if it is still working):
SELECT pic_with_logo FROM user WHERE uid = "..."
or use xfbml with <fb:profile-pic facebook-logo="true">
With jQuery and JS API you can make an FQL call:
FB.api({ method: 'fql.query', query: 'SELECT uid, pic_with_logo FROM user WHERE uid = me()' }, function(response) {
var user = response[0];
$('#container').append('<img src="'+user.pic_with_logo+'"/><br>');
});
also you can try:
pic_small_with_logo, pic_big_with_logo, pic_square_with_logo and the pic_with_logo i use in example.
here is the user table:
https://developers.facebook.com/docs/reference/fql/user/
Based on Tom's answer, Here is php example to get user's
$_json = json_decode(file_get_contents('http://graph.facebook.com/[FACEBOOK_UID]?fields=picture'));
if (isset($_json->picture)) {
header("Location: http://external.ak.fbcdn.net/safe_image.php?&url=" . $_json->picture . "&logo");
exit;
}
Here is what we do:
Query picture url via opengraph
Get the picture url from json object
redirect the page to facebook image handler with addition &logo to url