Upload photo to an album AND to wall in facebook through php. So we get a big picture on wall - facebook-graph-api

I manage to sent a photo from my server to a users album on facebook.
But this photo is not automaticly seen on his wall. And specifically it is not seen as a big photo, like how photos from albums are shown on a wall.
So I suppose I have to do a second request to tell facebook to put the photo on the wall.
I have these 2 requests:
$ret_obj = $facebook->api('/me/photos', 'POST',
array(
'source' => '#/var/www/cover/test.jpg',
'message' => $_POST['msg']
)
);
This returns for example:
[id] => 358313274248558 [post_id] => 100001736648729_358281023575116
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'message' => $_POST['msg'],
'object_attachment' => $ret_obj['id']
)
);
I have tried for the 'object_attachment' 358313274238558, 100001796648729_358281027575116 and 358281027575116. But facebook tells me that those are not correct.
So how on earth can we add a photo to a wall, which we just put in an album, and which we want to show in a large format (not as a little thumbnail).
If there is another way, without using albums, that is fine with me.
Please help. I know there have been a few questions already about photo uploads to facebook here on stackoverflow, I think I have read them all about 10 times already. It seems there is no answer yet. Somebody said we could post to /me/links but facebook doesn't seem to be able to handle links like http(s)://www.facebook.com/photo.php?fbid=358309510905631 anymore.
I have changed the ids in this post so they are not linked to actual stuff, they are here as examples.
Thanks
edit:
Ok, it seems a post of an image to an album is also a post of a big image to the wall IF the user allows the app to do public stuff. Because I was developing, I told the app to not do public stuff and only show stuff to me personally.
So there is no need to do 2 requests, just adding a photo to the album is enough to have it appear big on the users wall IF the user allows app activity to be public.
It is still somewhat confusing that a second request seems unable to also add the foto in a large size to the wall.

Related

How To Target Photo(s) For a Page Using Graph API?

I need help understanding whether or not this is the intended behavior or if it's something that is not supported. What I want to do is upload a photo to a Facebook page post that is targeted to a specific country.
The steps I take are:
1) Upload the photo to a public album (e.g. Timeline Photos)
2) Retrieve the uploaded photo id from the album
3) Create an attachment to the post with the photo id from step #2
The problem is that I'm now uploading a photo to a public album that is not targeted to a specific country. What I would like to do is to have BOTH the photo(s) and page contents be restricted by targeting. I see a picture parameter in the api, but I believe this is just for setting the page's profile picture.
Any ideas on how this may be accomplished or whether or not this is even possible? Any code examples would also be welcomed.
After playing around with this more I found that I had to set the 'source' parameter to point to a file in my local file system (pointing to a remote file did not work). Not sure if the latter may be accomplished. Also, you have to make a call to setFileUploadSupport with true.
Pseudo code via PHP:
//Create a temporary file somewhere
$contents = ...
$tmpfname = tempnam(sys_get_temp_dir(), $prefix);
$handle = fopen($tmpfname, "w");
fwrite($handle, $contents);
fclose($handle);
//Add to params
$params['source'] = '#' . $tmpfname
$fb = FB_sdk::instance(true);
$fb->setFileUploadSupport(true);
$fb->api('[url to page]/photos', 'POST', $params);

Artist info missing from Facebook Graph API /music.listens endpoint

I'm playing around w/ the /me/music.listens endpoint of Graph API and I have it working just fine. Except I can't seem to figure out how to get actual artist info to come back. I see the song and even the album (though that seems a little inconsistent too). But never any artist info.
Check the developer explorer here: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fmusic.listens
No artist info. Is this just not returned? I can't see how to specify this in a fields param list. FB's documentation of the actions is spotty at best so I figured I'd try here.
Thanks!
I've figured out a work around. It doesn't look like Facebook actually returns artist info. So you have to use the Spotify Lookup Service (http://developer.spotify.com/technologies/web-api/lookup/).
To break it down a little further, you start by pulling the music.listens feed from FB and you'll get info that looks like:
(
[song] => Array
(
[id] => 381659191902248
[url] => http://open.spotify.com/track/**2Vv27Gc5k5GgGW9jgtj1CS**
[type] => music.song
[title] => Follow Through
)
)
From there, you need to grab the bolded track ID.
Lastly, fetch the song metadata with this call to Spotify: http://ws.spotify.com/lookup/1/.json?uri=spotify:track:2Vv27Gc5k5GgGW9jgtj1CS
You'll be returned the album name, artist info, etc.
If someone knows a better way, lemme know!
You can retrieve artists informations on graph API with the song id :
https://graph.facebook.com/song_id?fields=data{musician}
ex : https://graph.facebook.com/697975930266172?fields=data{musician}
Old question I know, but you can retrieve related information such as both the song title and artist title in the same request using Graph API's 'field expansion'.
For example - Last 10 songs
me?fields=music.listens.limit(10){data{song{title,id},musician{id,title}}}
To retrieve more information from either the song or musician entities just tweak the fields requested.
Note, this requires user_actions.music permission

How to "Spawn" a Wall album in a new page

I am trying to post pictures to customers' pages. There may or may not be a "Wall Photos" album in the page.
In scenarios where there is not a pre-existing "Wall Photos" album how would I create / request the creation of a wall photo album?
I am using Koala and I can create albums, but I cannot create albums with type = "wall".
here is the code I am using to create / find albums:
def get_photo_album(facebook_id)
# Looking for a pre-existing WALL PHOTO album
p "============= Getting Wall Photos album for fbid #{facebook_id}"
album = get_album facebook_id, 'Wall Photos'
unless album
p ' ======= Album FAIL 1 - getting Photos '
album = get_album facebook_id, FALLBACK_ALBUM_NAME
unless album
p ' ========== Album FAIL 2 - MAKING Phtoos '
#graph_client.put_object facebook_id, 'albums', 'name' => FALLBACK_ALBUM_NAME
sleep 3 # wait 3 seconds to let facebook make and fiddle with new album
album = get_album facebook_id, FALLBACK_ALBUM_NAME
unless album
p ' ##################### UTTER ALBUM FAIL '
raise "Cannot use alternative photo album"
end
end
end
if album && album.length > 0
album
else
# ensure that there is an album.
raise "Cannot use alternative photo album"
end
end
def get_album(facebook_id, name)
params = {'name' => name};
albums = #graph_client.get_connections(facebook_id, "albums", params)
p "Found #{albums ? albums.length : 0} albums named #{name} for fbid #{facebook_id}"
albums = albums.reject do |a|
a['name'] != name
end
p "Found #{albums ? albums.length : 0} albums named #{name} for fbid #{facebook_id} AFTER filtering for name"
pp albums
albums.length >0 ? albums[0] : nil
end
end
And here is the Koala code I am using to put the picture itself
def put_image(facebook_id, params)
params = sanitize_params(params)
params = encode_necessary_params(params)
picture = URI.decode(params['picture'])
photo_album = get_photo_album(facebook_id)
photo_album_id = photo_album['id']
params = params.reject do |key, value|
key == 'metadata_type'
end
p ' -------------------------------------- PUT PICTURE ----------------------------'
p "fbid:#{facebook_id}, message: #{params['message']}, picture: #{picture}"
p ' -------------------------------------- PUT PICTURE ----------------------------'
out = #graph_client.put_picture picture, {:message => params['message']}, photo_album_id
Statsd.increment("posts")
out
rescue Exception => ex
handle_error(ex)
end
I have tried several variations including:
putting 'type' => 'wall' in the #graph_client.put_object parameters: doesn't post the image at all
creating an album named 'Wall Photos' - the album appears, but the posts don't look like wall posts.
To be clear: *The ultimate goal is for all posts to this album to have "big" previews - full column width, not tiled 1" previews. *
Any help would be appreciated.
What you're trying to do isn't going to be possible - the Wall Photos album is a special album which is generated from photos posted to feed, and there is no API available to post photos that way - if you post to /photos they go into an album specifically for the app.
However, all is not lost. If you're willing to embrace newer functionality, you'll both be able to meet your goal of having large photos in feed whilst also achieving greater viral potential for your app. The answer is Open Graph Actions. Specifically User Generated Photos in Open Graph
The process for this is relatively simple:
Create an Open Graph action and object for your app (do this from the Developer App Dashboard for that particular app), this can be anything depending on what your app does, but, for example, Instagram uses 'took' as their OG action and 'a photo' as their OG object. This means that posts from that app look like "Matthew took a photo with Instagram" and show the photo below. Which action you want to use is up to you.
Request publish_actions permission from your app users, if you haven't been already.
Make API calls to:
https://graph.facebook.com/me/YOURAPPNAMESPACE:YOURACTION?
YOUROBJECTTYPE=URLWHEREYOUROGOBJECTISLOCATED&
image[0][url]=URLOFPHOTOYOUWANTTOADD&
image[0][user_generated]=true
You'll also need to sign this API call with the access token for that user, or I believe, if you have publish_actions for that user, you can make the above call to /USERID instead of /me and use your app's access token and it will work.
As you can see from the documentation this will give you the full sized photo that you're after and having it be created by an Open Graph action allows for a whole host of extra virality if you incorporate extras such as OG action links, authenticated referrals etc.

How can I get facebook albums with images from users

I am creating a facebook app and i want to display the users albums with the cover image, i have tried with code #1 but it is really really slow as i make a facebook api call in the foreach which makes my app take forever, so I am looking for another way to make the api call just once and get all the info, so i tried with FQL multi query (code#2) but now i have a problem because if the album has no image it won´t return nothing, so please check my codes and if you have any idea how i can do this i will greatly appreciate it
code#1
$albums = $facebook->api('/me/albums?limit=0&fields=id,name,count,cover_photo');
foreach($albums['data'] as $album)
{
// get all photos for album
$photos = $facebook->api("/{$album['id']}/?fields=picture,name,count");
$foto = $photos['picture'];
$nombre = $album['name'];
$id = $album['id'];
$count = $album['count'];
$cover_photo = $album['cover_photo'];
$nombre = $nombre." (".$count.")";
echo "<li> <img src=\"https://graph.facebook.com/{$cover_photo}/\" alt=\"$nombre\" /> </li>";
}
code#2
$multiQuery = '{
"albumes":"SELECT name,cover_pid,object_id,size FROM album WHERE owner=me()",
"portadas":"SELECT src_big FROM photo WHERE pid IN (SELECT cover_pid FROM #albumes)"
}';
$param = array(
'method' => 'fql.multiquery',
'queries' => $multiQuery,
'callback' => '');
$queryresults = $facebook->api($param);
foreach($queryresults[0]['fql_result_set'] as $album)
{
$nombre = $album['name'];
$id = $album['object_id'];
$count = $album['size'];
$nombre = $nombre." (".$count.")";
echo "<li> <img src=\"https://graph.facebook.com/{$cover_photo}/\" alt=\"$nombre\" /> </li>";
}
so i tried with FQL multi query (code#2) but now i have a problem because if the album has no image it won´t return nothing
Can’t really see your problem there. If I try your queries using the Graph API explorer, it gives me all my albums, and a cover photo for each one that has one. (So that’s 4 albums and 3 photos for me.)
If you’re having trouble to tell which photo is from which album – then just include the aid field in both queries.
it is really really slow as i make a facebook api call in the foreach which makes my app take forever
Of course it does, because each API call means another HTTP request, and those are slow.
If the FQL method doesn’t give you what you want, then make your API requests into batch requests – that reduces the number of HTTP requests, and therefor should speed things up quite well.

Is it possible to ADD Hyperlink in Facebook Status Message or Photo album Message?

//Get album ID of the album you've just created $album_uid =
$create_album['id']; //Upload a photo to album of ID...
$file='img/'.$fbid.'.jpg'; //Example image file
$photo_details = array( 'message'=> 'Are you Good or Evil?
===>http://www.facebook.com/ithefunpage', 'image' => '#' . realpath($file) ); $upload_photo =
$facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
$upphoto = $upload_photo['id'];
I have this code above and it will create an album to the user with the status message "Are you Good or Evil? ===> http://www.facebook.com/ithefunpage" now i just want to ask if it is possible to hyperlink the url "http://www.facebook.com/ithefunpage" into "Personality Quiz" or should i say is it possible to add hyperlink in facebook status message or Photo uplaod message?
No. This is not possible. I'm pretty sure about that. and even the link in message is against facebook's t&c as far as I know.
Previously facebook status has an option to add ONE hyperlink in a special way, but now it is deprecated.