I'm confident about posting multiple photos to a fan page album through a common batch request with PHP, and I also know how to use che "no_story" command to hide the wall posts showing each image just uploaded. What I need to know is if it's possible to show an unique wall post on the fan page showing the whole upload, like the standard Facebook behavior when you upload more pictures using the web interface, and not one post for each photos.
This is the closest I have got:
$attachment = array
(
'access_token'=>$fanPageAccessToken,
'object_id' => $AlbumId,
'message' => $AlbumDesc,
'link' =>$AlbumLink
);
$result = $facebook->api($fanPageId.'/links/','post',$attachment);
}
I get the variables by querying the albums associated with the fanpage:
$fanPageAlbums = $facebook->api($fanPageId . '/albums/');
foreach ($this->fanPageAlbums['data'] as $fanPageAlbum) {
if ($albumId == $fanPageAlbum['id']) {
$albumLink = $fanPageAlbum['link'];
$albumDesc = $fanPageAlbum['description'];
break;
}
}
The key thing is your are posting to the links part of the graph, not the feed.
This works in that it will produce one big picture and three thumbs below it, as you would expect. However, it doesn't appear on the feeds of friends properly.
I've been struggling with this for ages, and the above is the closest I have got to mimicing exactly the facebook behavior. If you get any further please let me know!
Related
I'm running in circle with this problem so I submit it here.
I have created a facebook fanpage and a website for my mother to promote her music. Since she is quite used to facebook I decided that instead of creating a whole backoffice, the website would simply display the fanpage's posts, photos and events. I do this with simple calls to
$data= $fb->api('/'.PAGE_ID.'/posts?fields=id');
for example (or 'notes', 'events'...). The problem is that I have to use a specific access token that I get from my own 'me/accounts/' permissions. From time to time (say every month) I have to go to the Graph API Explorer, get that token, and save it in the website config.
I'm wondering if I couldn't generate that access token server-side on my website, but I can't seem to make it happen. the facebook PHP SDK can't acces my api('/accounts') graph results unless I'm the authentified user (obviously), and a call to api(PAGE_ID.'?fields=access_token') only returns the page's ID.
What Am I doing wrong? can the facebook php sdk make api calls on my behalf (independently of users)?
More info : I created the fanpage, and a simple app called feed reader, with *manage_pages* permission. I'm the only user that authorized that app, and I don't want the user on the website to have to login (why should they? it's my fanpage, why would I need their *manage_page* permission?).
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
To be honest I kinda feel that public posts sould be public in the graph api too, but I'm sure there is a reason.
You can get to any users public posts like so:
Note: this assumes you are using the PHP SDK here http://developers.facebook.com/docs/reference/php/
$facebook = new Facebook(
array(
'appId' => 'fb_app_id',
'secret' => 'fb_secret',
)
);
$url = '/' . 'fb_username' . '/posts?fields=id,name,created_time,message,story,type&limit=10'; // you might need to screw with this some
$page = $facebook->api($url);
while(count($page['data']) > 0)
{
foreach($page['data'] as $fb_post)
{
// USE THEM DATAS
}
// Keep retrieving next pages until spent
$url_parts = parse_url($page['paging']['next']);
$url = '/' . 'fb_username' . '/posts?' . $url_parts['query'];
$page = $facebook->api($url);
}
this is an example from: https://github.com/fyaconiello/WP_Social_Network_Posts/ which pulls FB posts in and saves em as WP posts. It was written to answer a different question.
According to Facebook's Graph API documentation (here), you can access various sizes of a user's profile picture through URLs such as:
https://graph.facebook.com/(userid)/picture?type=small
https://graph.facebook.com/(userid)/picture?type=large
You'll notice that the first resolves to a url ending in _t.jpg (the small thumbnail) and the second ending in _n.jpg (the large image). So far so good. Equivalently, we should be able to query for these images like this:
https://graph.facebook.com/(userid)?fields=picture&type=small
https://graph.facebook.com/(userid)?fields=picture&type=large
This latter format worked as expected for many months, until just a few days ago when it suddenly started ignoring the "type" parameter entirely - everything now resolves to an image ending in _q.jpg, which is the default if no "type" is specified. As a result, I can no longer figure out a way to query for the large image in PHP (my real problem). It used to work like this:
$pic = $facebook->api('/me', array('fields' => 'picture', 'type' => 'large'));
...but as described above, "type" has spontaneously started being ignored. I've spent several hours scouring their documentation but haven't been able to find any reference to what has changed, or the "new" way this should be done - any pointers would be hugely appreciated...
EDIT:
None of the following work, either (returns nothing):
$pic = $facebook->api('/me/picture', array('type' => 'large'));
$pic = $facebook->api('/(my_uid)/picture', array('type' => 'large'));
$pic = $facebook->api('/me/picture/?type=large');
$pic = $facebook->api('/(my_uid)/picture/?type=large');
Basically, since Facebook broke things a few days ago there doesn't seem to be any way to get a non-default picture size from PHP. You can try out some of the calls yourself from the Graph API Explorer (here).
Other related/relevant links:
http://stackoverflow.com/questions/2978761/facebook-graph-api-will-not-give-me-picture-data
http://stackoverflow.com/questions/7718704/requesting-picture-for-event
You must request the API with the field_expansion syntax
These api requests works :
$results = $facebook->api('/me', array('fields' => 'picture.height(300).width(300)'));
$results = $facebook->api('/me', array('fields' => 'picture.type(large)'));
As described in this bug on Facebook, you can request this via the new API "field expansion" syntax.
This works for me:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
I found a workaround - profile pictures of various sizes can still be accessed via an FQL query:
$pic = $facebook->api(array('method'=>'fql.query', 'query'=>"SELECT pic_big FROM user WHERE uid=$fb_uid"));
("pic_big" is equivalent to "type=large" - see here).
This still doesn't explain why the GRAPH call suddenly broke though, or why image sizes don't seem to be accessible via Graph at all anymore (which I'd still like to know)...but at least there's some way to get the other size photos.
Gotta love Facebook and their top-notch reliability...
I am trying to upload a photo from my server to an album on my page.
I have the following code to send the photo:
$argsFeed = array( 'source' => '#' .$FILE_PATH,
'published' => true,
'message' => $caption);
try {
$imageId2 = $facebook->api('/'.$ALBUM_ID.'/photos', 'post', $argsFeed);
} catch(FacebookApiException $e) {
$result['status'] = "error";
$result ['message'] = $result ['message'] . ' ||| error posting photo to page 164264490295119. facebook says: <BR/>' . json_encode($e->getResult());
}
I have the following permissions:
publish_stream,user_photos,manage_pages
I always get success for the api-call, with a photo id, but the photo doesn't go anywhere.
The exact same photo was posted to my (the user's) wall as well, so the photo can't be the problem.
my guess is that it does get posted somewhere, since there's no exception, only I don't know where it's posted.
anyone has a clue?
I get photo-id's like this one:
10151091881973938,633203937_10151091735008938
but I don't know what to do with them - how do I look them up in the graph?
It's difficult to diagnose this without some more context. Is $facebook->api performing a POST?
However, the fact that your retrieving photo-ids without image extensions leads me to believe that your problem could be that the image extension isn't making its way to the Facebook POST; thus you can't display an image that doesn't have a .jpg or .png extension. This would explain why it accepts the file as it is of type=image
I get photo-id's like this one: 10151091881973938,633203937_10151091735008938 but I don't know what to do with them - how do I look them up in the graph?
The first part before the comma is definitely your photo’s id in the Graph.
That’s your photo object on the Graph:
https://developers.facebook.com/tools/explorer?method=GET&path=10151091881973938
That’s one of the actual image URLs on Facebooks CDN:
https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc6/283597_10151091881973938_1730322674_a.jpg
And that’s the display URL of your photo on facebook.com displaying it as one of your photos in your album:
https://www.facebook.com/photo.php?fbid=10151091881973938&set=p.10151091881973938&type=1
The second part, 633203937_10151091735008938 is obviously your user id combined with your photo’s id. Did you get them all as one string, as you posted them, photo_id comma userid underscore photo_id, or did you just post them as this?
Normally I would expect just the photo id to be returned from a successful photo post through the API.
The question is pretty much in the title, but to be more specific, I'm working on a facebook contest for a client in which people have to upload photos to take part in it after accepting rules and subscribing, etc.
After going down a long road full of deceptions
(here's what I tried that didn't work in the end:
uploading to the user's album then tagging the page: nope, can't tag a page
uploading to a public album in the page, like "fan photos", or wall photos? can't find anything AT ALL about a way to do this, though it would've been my preferred way.)
So, I ended up having an idea: I would do this in two steps. First, the user subsribes and uploads a photo to my PHP server. Then, another, different application with permissions on the account that has the page, would take control of it, upload all the photos at 5 minutes intervals (meaning, you subsribe, 5 minutes later, your photo's uploaded.)
So far, so good; I don't like the logic behind this, but it's the only way I found! So, I did the base, I'm able to post a photo with a caption as the page in a dedicated app album.
BUT! I can't tag anyone in those photos. Maybe you can't tag as a page, maybe you can't tag in page albums, maybe I don't have the permissions required (I have stream_publish, user_photos, friends_photos, offline_access, and I could add anything if I need to since it's a private-use app anyway). Oh and, the user I'm trying to tag is the admin for both the app and the page (and he likes the page). I don't know, but it's driving me crazy. I hate the official documentation, there's no example code, you have to figure out most of the things, go through trial and error or search on the web for people who did so and shared how to do things. Not nice when you have little time to complete a project for a client without busting the budget.
Anyway, here's my error I keep getting whenever I try to tag someone to a photo from any album:
OAuthException: (#322) Invalid photo tag subject
And here's the code I'm using to upload a photo from the server to facebook.
if ($user) {
try {
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
// First method, at the same time as upload. Upload works but no tags
$args = array(
'access_token' => $page_info['access_token'],
'source' => '#' . realpath($FILE_PATH),
'message' => "test"
'tags' => array(
array(
'tag_uid'=> "MY_USER_ID",
'x' => 0,
'y' => 0
))
);
$post = $facebook->api("/$page_id/photos","post",$args);
$postID = $post['id'];
// Second method I'm trying. No tags.
$tag = $facebook->api("/$postID/tags/MY_USER_ID","post");
print_r($tag);
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Any help would be appreciated. Thanks in advance!
EDIT :: Now I got it partly working using the second part in the code, but only if I remove the "access_token" parameter from the photo posting first. Basically, it only works if I upload it to a personal album. But that's as far as it gets from what I want. When I upload it to the album from the page, it says I asked for tag requests, but on my personal account which I tagged, I don't receive anything. Baaaah.
RE-EDIT :: After much tries, it seems I can't tag someone as a page or in a page album. I'll try to find an alternative, I guess.
i'm trying to get all the images from a facebook group using facebook API
i have a problem i can't get all the photos using
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
http://wiki.developers.facebook.com/index.php/Photos.get
what i'm using now is the method
$albums = $facebook->api_client->photos_getAlbums($uid, NULL);
http://wiki.developers.facebook.com/index.php/Photos.getAlbums
and then loop for ever album on
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
then i add every new array results to my big array
$big_array = array_merge($big_array,$result_array_from_that_call);
2 problems occurs here :
1- sometimes this calls fails - i think because of too many calls per second -
2- the request takes a v.long time to process
is there a better way to do that?
Thanks guys
Cheers
EDIT :: i tried to get all the images using
$facebook->api_client->call_method('Photos.get', array('subj_id' => $uid));
and using $uid as the group ID but that's doesn't work " don't know why maybe because all the images is listed in groups "
the best solution was to output the album and then the user clicks on an album and check the images inside it