Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph API new feed post object-Attachment not showing

I'm having a strange problem with the graph API, the below code used to work for me adding a post to a users news feed with a thumbnail of the attached photo (referenced in 'object_attachement' parameter).

However now the post is created as expected however the thumbnail is empty. The photo_id I am using exists in the user's photo collection.

Results of below code now.

    $photo_ID = "3415678920211";//Valid Facebook Photo ID...        
    $facebook = new Facebook($config);

    $attachment =  array(
            'access_token' => $user_token,
            'message' => "Test Message",
            'caption' => "THis is a Caption",
            'name' => "Test Name",
            'description' => "This is a description",
            'link' => 'http://url.com/',
            'object_attachment' => $photo_id,
    );

    $response = $facebook->api("/".$userID."/feed/", 'POST', $attachment);

Am I doing something wrong? I am sure this did use to work and wonder if something changed in the API underneath me.

[Update] I noticed that this seems to happen when I specify both link & object_attachment in the same POST. If I remove the link param from the above then I get a slightly better update however this isn't great as the main reason I want this post to exist is for the addition of the link.

like image 518
Shaun Bohannon Avatar asked Dec 15 '12 23:12

Shaun Bohannon


3 Answers

I am assuming user gave the permission for user_photos / friends_photos. Since you have the photo_id, you may try this.

$pic = $facebook->api("/PHOTO_ID");
$pic_url = $pic->source;

$attachment =  array(
    'access_token' => USER_ACCESS_TOKEN,
    'message'      => "...",
    'caption'      => "...",
    'name'         => "...",
    'description'  => "...",
    'link'         => URL,
    'picture'      => $pic_url
);

ADDED

You need to store the image some where locally ,in a local server . due to this article

like image 128
Sahil Mittal Avatar answered Nov 14 '22 09:11

Sahil Mittal


I think the 'object_attachment'=>$photo_id won't work any more. You should change it to 'picture'=>$photo_url

$photo_Url = "link to your photo";//Valid Facebook Photo ID...        
$facebook = new Facebook($config);

$attachment =  array(
        'access_token' => $user_token,
        'message' => "Test Message",
        'caption' => "THis is a Caption",
        'name' => "Test Name",
        'description' => "This is a description",
        'link' => 'http://url.com/',
        'picture' => $photo_Url,
);

$response = $facebook->api("/".$userID."/feed/", 'POST', $attachment);

You can find more Here

like image 3
Jonathan_Ng Avatar answered Nov 14 '22 11:11

Jonathan_Ng


you have to permission pubish_stream on your app and then try this using curl:-

$attachment =  array(
        'access_token' => $access_token,
        'message' => 'i m success to using graph api for post wall',
        'name' => 'Wall Post using graph api',
        'link' => 'www.mysite.com',
        'description' => 'Using the Graph API, any Facebook users Wall feed may be accessed by using this URL:',
        'picture'=>'http://example.com/images/noimage.png'
 );
$url = "https://graph.facebook.com/$facebook_id/feed";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
print_r($result)
like image 3
Rakesh Sharma Avatar answered Nov 14 '22 10:11

Rakesh Sharma