Upload image to facebook fan page using Graph API - facebook

I am trying to upload an image through my application with Facebook Graph API to an album of my fan page. Although I provide the albumID like a parameter for uploading the image, it is uploaded in an album named to my application name Photos on my own profile. The album of the fan page stays empty. I tried also with sending the pageID of my fan page instead of albumID, but the result is the same.
I thought there is a problem with access token but with same accessstoken i can post links to page.
The code I use for the upload is:
$args = array(
'access_token' => $access_token,
'message' => "$baslik",
"source" => '#' . realpath($file)
);
$post_id = $facebook->api("/$page_id/photos","post",$args);
Please give me ideas how can I upload the image to the fan page and not to my own profile album.

I think you havent got Manage Permission.
Check this for more info : Upload image to facebook fan page using API

Related

Facebook wall post with object attachment using iOS SDK 3.5.2

Facebook recently changed its publish API to prevent post on another user's wall and we should use their share dialogue.
Facebook documentation about publish
I need to share a photo to my friend's wall and I could achieve this using /USER_ID/feed post by specifying a post parameter named object_attachment. Now they have removed /USER_ID/feed post on another user's wall.
So my chances are to follow their share dialogue. But share dialogue will not accept object_attachment parameter of any kind and I can not share photo to my friend's wall or timeline.
Can any one help me?
As you rightly mentioned, Facebook have removed the ability to post via the graph API to another user's feed.
You can, however, use their FB.ui({ method: 'feed' }) feed dialog Javascript dialog combined with target_id: to prompt the user to post to one of their friends' walls.
The accepted parameters are listed on the documentation page and no, you can't attach anything.
One alternative is to create a unique resource for each photo you would have uploaded which contains open graph meta tags, with which you can describe a thumbnail (og:image and og:image:secure_url).
Another alternative is to upload the photo to the current user's album, then to tag the user's friend in that photo:
//Tag friend_to_tag_id at position (x_coordinate, y_coordinate)
$post_url = "https://graph.facebook.com/"
.$photo_id . "/tags/" . $friend_to_tag_id
. "?access_token=". $access_token
. "&x=" . $x_coordinate . "&y=" . $y_coordinate . "&method=POST";
$response = file_get_contents($post_url);

Embedding Facebook photo albums with like button, on my website

Can I do something like this?
I want to have all the photos from my fan page, embedded on my website.
Want to have the option to like each photo - must.
Want that each photo will have a link to the real URL on Facebook - must.
Would like to share and comment as well but not as important.
Please let me know if you have an idea of how I can do it.
I saw a lot of examples but nothing that include these things.
Thanks!
Getting some of the photos is easy. Getting all of the photos is nearly impossible. Start with a Graph API call to the photos object.
To get the photos, create and app, install the PHP SDK on your site. This code should get you started.
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
);
if (!class_exists('Facebook'))
include_once 'PATH_TO_SDK/facebook.php';
$fb_object = new Facebook($config);
$photos = $fb_object->api('PAGE_ID_OR_USERNAME/photos', 'GET');
printf('<pre>%s</pre>', print_r($photos, true));
You'll need to iterate through these results to get more than 15 of your photos. Photos that aren't marked as "Public" won't be returned by this API call.
To create a like or a comment, you need to auth the user and then POST to the Graph API using the photo id.

Upload image to Facebook Wall / Feed via Graph API

I am trying to upload local images directly to a pages feed (i.e. "Wall Photos" album).
This is the code that I think should work:
<?php
$facebook = new Facebook(array(
'appId' => $the_app_id,
'secret' => $this_app_secret,
));
$facebook->setAccessToken($the_access_token);
$facebook->setFileUploadSupport(true);
$attachment = array(
'message' => $the_post_body,
'name' => $this_image_name,
'picture' => '#' . $the_absolute_path_to_image
);
$result = $facebook->api('/me/feed, 'post', $attachment);
But this code just yields a plain text wall post with the contents of "message" (i.e. picture field is seemingly ignored). I have also tried "/page_id/feed", same result.
Now, simply changing the endpoint to "/me/photos", does upload the photo to a 'normal' album with the name of the app, but I want it to look as much like a normal post as possible and so hence into the "Wall Photos" album).
I realise that I could achieve this by querying the graph with FQL to find the object_id of the "Wall Photos" album, but if it does not exist it would require extra permissions to create it and I would rather keep permissions as simple as possible.
If anyone could point out how to upload photos to "/me/feed" I would greatly appreciate it.
But this code just yields a plain text wall post with the contents of
"message" (i.e. picture field is seemingly ignored). I have also tried
"/page_id/feed", same result.
You can only give the link to picture but not the data.
Now, simply changing the endpoint to "/me/photos", does upload the
photo to a 'normal' album with the name of the app, but I want it to
look as much like a normal post as possible and so hence into the
"Wall Photos" album).
Ye, it creates an album by default based on app. if already exists, it uploads to album. And generates a post.
I realise that I could achieve this by querying the graph with FQL to
find the object_id of the "Wall Photos" album, but if it does not
exist it would require extra permissions to create it and I would
rather keep permissions as simple as possible.
You cannot upload to fb for me/feed end point. You should store in your server/s3/some service and give the public url to me/feed params.

How to share a link to facebook fan page as admin of fanpage with facebook API

I have a issue with the facebook API. I created a fan page and set admin of page which is my account facebook. After that, I want to use Facebook API to post a feed to fan page. In this case, I have tested with 2 types : status message and share link.
1>Post a message to fanpage :
$publishStream = $fb->api("/" . $fbPageId ."/feed", 'post',
array(
'message' => 'test ' . time() . ' http://example.com',
)
);
Result : I've posted to fanpage success and owner of feed was fanpage.
2> Share a link to fanpage
$publishStream = $fb->api("/" . $fbPageId ."/feed", 'post',
array(
'link' => 'http://example.com',
)
);
Result : I've posted link to fanpage success and owner of feed was user. This feed will show in Recent Posts by Others on ABC Page (ABC is name of fanpage).
Anyone have got same issue like me ? Thanks.
Replace feed with links
$publishStream = $fb->api("/" . $fbPageId ."/feed", 'post', (...)
to
$publishStream = $fb->api("/" . $fbPageId ."/links", 'post', (...)
I just confirmed this behavior, it's really unexpected. When using a user token and posting with only the message attribute set it posts as the page.
The "Always comment and post on your page as Page.." box is unchecked in the admin settings, which is even weirder. They must be using different back ends for posting messages, as they don't have to scrape outside url links for og tags.
Anyway, use page access_tokens from the graph.facebook.com/USER_ID/accounts endpoint for consistent behavior.
I am having the same issue. And I am using Page access tokens each time. If the post has a "message" it goes in on the Page (and thus shared with those who like the page). If it only has a "link" it goes to my personal news feed and is shared only with friends.
And by the way, I tried including both "message" and "link" and it went on my personal new feed, not the page.
What kind of access token did you use each time? Looks like you used a page access token the first time, and an user access token the second.

Upload photo to fanpage from application user

I have a Facebook application in which a user can upload photos to a facebook fanpage. I am having trouble figuring out how to upload the photo as the user that is using the application. Currently I can have the fanpage upload the photo as itself, so the fanpage loses the author of the photo.
To do this I am grabbing the fan page's auth token(which I am assuming is the reason the app is posting as the fan page) and using that to pass to the "photos" method of the api. I am using the AS3 api, but I am sure the concept is the same no matter which api I am using.
var values:Object = {message:"message here", name:"title here"};
values.access_token = fanPageAccessToken;
values.image = file;
Facebook.api('fanPageId/photos/', handleUploadComplete, values,'POST');
When I change to the user's access token the image is uploaded to the user's photos. Even though I am specifying the fanPageId, it gets uploaded to the user's photos.
I am struggling here. Does anyone have an idea I can try, or some insight to share?
Thank you so much, I appreciate your time!
I've tried every possible API combination to post a photo to a page from the user, but it's no use. A user cannot post a photo to a page. Even creating an album on the page and then posting to that doesn't work.