I have a cache of pictures in my website, and I need to upload these photos to my Facebook fan page 4-5 times a day. My code creates an album and also uploads the photos to the album, however, these photos do not appear in the timeline.
So my question is, how do I upload photos to my fan page such that they appear on the timeline, on the wall. The language in use is PHP
Any help is greatly appreciated.
Thanks
Edit 1:
Here is the code:
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => "AAAAAAAAAA",
'secret' => "BBBBBBBBBB",
));
$fanpage_token = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ";
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'test album',
'name'=> 'album'
);
$create_album = $facebook->api('/PAGE_ID/albums', 'post', $album_details);
$album_uid = $create_album['id'];
echo $album_uid;
$img = '7newx.jpg';
$args = array(
'message' => 'Random message',
'image' => '#' . $img,
'aid' => $album_uid,
'no_story' => 1,
'access_token' => $fanpage_token
);
$photo = $facebook->api($album_uid . '/photos', 'post', $args);
?>
Ok, so I guess you tried removing the no_story and found that it didn't affect the timeline. Thats what I found too.
What you have to do is make another post, but this time, as a link. You need to use your array $photo, which was returned from your first post. If you examine that you should see it has a single element called ['id'], containing the id of your uploaded photo.
You need to turn that into a link that facebook would use to display. This is simple.
if (isset($photo['id']))
{
$message = "My latest photo";
$link = "https://www.facebook.com/photo.php?fbid=".$photo['id'];
$attachment = array
(
'access_token'=>$fanPageAccessToken,
'type' => 'photo',
'message' => $message,
'link' => $link
);
$result = $facebook->api($fanPageId.'/links/','post',$attachment);
}
I am assuming you can work out what $fanPageAccessToken and $fanPageId are.
If you do that, you should get what you want.
Related
I'm using PHP facebook API 3.2.3 to connect to facebook and publicate messages from my page.
Until recently it was working find, but now messages are not publicated.
When i copy returned by FB message ID to create link, it is there, but not on my facewall.
I can accesss to my message by link like this:
https://www.facebook.com/permalink.php?story_fbid=800134770033938&id=659754124150164
It says, that i've publicated link on my fanpage, but it is not visible on wall.
Ofcourse there are all necessary permissions.
Code looks like this:
$fb_fanpage_name = $fb['FBFanpageName'];
$fb_access_token = $fb['FBAccessToken'];
$fb_app_id = $fb['FBApp'];
$fb_secret = $fb['FBSecret'];
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => TRUE,
));
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url
);
try
{
$res = $facebook->api('/' . $fb_fanpage_name . '/links', 'post', $post);
} catch (Exception $e)
{
$this->zp($e->getMessage());
}
According to FB API on page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/links/ - you can't posting links like this.
Apparently You want post message to feed.
So to do this try :
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url,
'message' => 'try me!'
);
$facebook->api('/'. $fb_fanpage_name .'/feed', 'POST', $post);
Update : to find this look at page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed
I'm trying to post a message with picture (from a public URL, not from my albums) to group's wall:
$response = $facebook->api("/$group_id/feed", "POST", array(
'access_token=' => $access_token,
'message' => 'This is a test message',
'picture' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
)
);
Everything is fine, but I can't see a picture itself:
What am I doing wrong? Thanks in advance!
While posting a feed, you must specify a link along with a picture if want to add a picture to the feed; else its not a feed. Logical right?
Code:
'access_token=' => $access_token,
'message' => 'This is a test message',
'link' => '{link-to-share}',
'picture' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
If you dont want link, but just a picture, then you should simply upload the picture instead- by using /photos
Code:
$response = $facebook->api(
"/$group_id/photos",
"POST",
array (
'url' => '{image-url}',
)
);
Yes there's almost a hundred same question as this. i have tried the answers provided and searched on forums etc...but all didn't work for me :( . I a have an app on facebook. I want to post a link to my page's timeline. (NOT ON USER'S TIMELINE). how can i do this using php sdk? i found this post How do you post to the wall on a facebook page (not profile). it's very informative yet i still dont know excatly what to do. i also rea this post Post to Facebook Page Wall. still no help for me. this is what i have at the moment:
require_once('libs/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
$attachment = array(
'link' => $post_link,
'message' => 'Another Super Story!',
'actions' => array(
array(
'link' => $post_link
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
i saw this code but i dont know what the number stands for
$facebook->api('/123456789/feed', 'post', array(
'access_token' => $token,
'link' => 'http://www.example.com'
));
please help me. im desperate to solve my problem. i dont know what to do. thank you in advance.
EDIT:
i now have this code as i have refered to this question Facebook API: How to post to my own wall page? . but still, not working for me. anyone who could tell what i'm missing?
$page_access_token = "2xxxxxxxxxxxx|bxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
if($page["id"] == $page_id) {
//$page_access_token = $page["access_token"];
$page_access_token = $facebook->api("/".FB_PAGE_ID."?fields=access_token");
break;
}
}
$attachment = array(
'message' => $post_msg,
'link' => $post_link,
'access_token' => $page_access_token,
);
$facebook->api("/".FB_PAGE_ID.'/feed', 'POST', $attachment);
Before using facebook api methods, you need get access token. May be this example will be useful for you https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php
im posting to a users wall, i have the id and everything else, but i cannot seem to "tag" friends, here is the code (I followed their documentation https://developers.facebook.com/docs/reference/api/user/#posts):
$tags = $tag1 . $tag2 . ',someID';
// tag 1 and tag 2 are also IDs of users, seperated by a comma only, no whitespace
$place = '110343502319180';
$attachment = array(
'access_token' => $access_token,
'message' => $message,
'link' => $link,
'name' => $title,
'description' => $desc,
'picture'=>$pic,
'place'=>$place,
'tags'=>$tags,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$post_url = '/' . $row['uid'].'/feed';
$postResult = $facebook->api($post_url, 'post', $attachment );
I specify a place, and 3 user IDs, to tag, it does not work.
For info, the story does get posted, but the tag and the location are not defined in it..
I am trying to upload a photo to a specific page, which is working, but now I would like to tag the current authenticated user in that photo I have just uploaded to the page.
Here is my code,
$result = $facebook->api('/PAGE_ID/photos', 'post', array(
'source' => '#pic.jpeg',
'message' => 'Ninja of the month!!!',
'access_token' => 'PAGE_TOKEN',
'tags' => array(array(
'tag_uid'=> CURRENT_USERS_UID,
'x' => 0,
'y' => 0
))
));
when I try that I get this error Fatal error: Uncaught OAuthException: (#322) Invalid photo tag subject thrown, I have made sure that the page allows users to be tagged, and that I have the required permissions, status_update,publish_stream,user_photos,offline_access,manage_pages.
Any idea why this could be happening and how I can fix it?
I think you might need to update the tags with the different access_token (user's access_token).
something like this might work
$facebook->setFileUploadSupport(true);
$args = array(
'access_token' => 'PAGE_TOKEN',
'message' => 'MESSAGE',
'image' => '#' . realpath($path_to_user),
);
$data = $facebook->api('/ALBUM_ID/photos', 'post', $args);
$token = $facebook->getAccessToken();
$argstag = array('to' => 'USER_TO_TAG');
$argstag['x'] = 40;
$argstag['y'] = 40;
$argstag['access_token'] = $token;
$datatag = $facebook->api('/' . $data['id'] . '/tags', 'post', $argstag);
I think this may be a bug, I think we may be having the same problem:
http://facebook.stackoverflow.com/questions/8425605/cant-tag-users-on-facebook-page-php-sdk-graph-api
This is a link to someone who has posted the issue as a bug to facebook. I don't know if anyone is working on this but please add your vote to getting it fixed and leave a comment. I'm sure that a LOT of people would like this functionality!
http://bugs.developers.facebook.net/show_bug.cgi?id=17947