Publish post with picture and link on event's wall - php

Is there a way to publish a post with a picture and a link on an event's wall? Currently I can publish only statuses (messages). On the user's wall there is no such issue. I've tried the new Graph API as well as the old REST API ('stream.publish' method) with no success (using PHP SDK).
Thank you in advance.
The code I use for Graph API:
$attachment = array(
'message' => 'my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'description' => 'this is a description',
'picture' => 'link to an image',
'actions' => array(array('name' => 'See recipe',
'link' => 'http://www.google.com'))
);
$facebook->api('/'.$eventID.'/feed/','post',$attachment);
The code for REST API:
$url = "https://api.facebook.com/method/stream.publish?".$access_token;
$attachment = array('name' => 'This is my demo Facebook application!',
'href' => 'http://news.google.com',
'description' => 'It is fun!',
'media'=> array(array(
'type'=> 'image',
'src' => 'link to an image',
'href' => 'http://www.google.gr'))
);
$params = array();
$params['message'] = "my message";
$params['attachment'] = json_encode($attachment);
$params['target_id'] = $eventID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
curl_close($ch);
As I mentioned above, both is working if I publish on user's wall. On event's wall a status message is published showing only the content of 'message' parameter.

I have the same problem. The event wall post only appears as text message, it is not possible to post a "link" or a "post" to the event wall via any API.
The same post appears differently on the users wall or on the event wall.
The behavior can be tested here:
http://developers.facebook.com/docs/reference/rest/stream.publish/
Just fill out the form and post the same message with a valid attachment once to the users wall and once with a target id (for an event) and see the difference.
This behavior is not documented and also google gives not much help.
Any workarounds or explanations would be appreciated.
Here is a demo attachment (working on the users wall):
{
"name": "Test name",
"href": "http://www.google.com",
"description": "Test Desc",
"media": [
{
"type": "image",
"src": "(any image)",
"href": "http://www.google.com"
}
]
}

Related

Forbidden error 403 in Unification Engine API while sending message

I am using #unificationengine API to send message on facebook.
Details I have given while registering my APP on facebook:
site url : http://localhost:3000
Email adress and other required details
In unificationengine API I have used all the curls mentioned in their documentation step by step as follows:
1. Created user using API key and Secret
2. Added connection
3. test connection
4. Refresh connection
5. Send message
All 4 gave 200 success code but send message gives 403 fobidden error.
The curl I am using for this is as below:
$post_msg = json_encode(
array(
'message' =>
array(
'receivers' =>
array(
array(
'name' => 'Me',
'address' => 'https://graph.facebook.com/v2.5/me/feed',
'Connector' => 'facebook'
),
),
'sender' =>
array('address' => ''),
'subject' => 'Hello',
'parts' =>
array(
array(
'id' => '1',
'contentType' => 'text/plain',
'data' => 'Hi welcome to UE',
'size' => 100,
'type' => 'body',
'sort' => 0
),
),
),
)
);
$ch = curl_init('https://apiv2.unificationengine.com/v2/message/send');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD,'3f43c37b-a066-4cc4-a3be-33faf72d6a21:2722fc72d-5d347-4a3a-a82b-0c1ss51aafb4');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_msg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
return ['label' =>$response];
I am trying to figure this. But no success.
Again I like to mention that I am using this on localhost, could that be the reason for forbidden error? If so then facebook graph api from which we get access token should also give such error.
Earlier I have posted this question, here also I didn't find right solution. I added Curl options that is mentioned in comment of my question there but it didn't changed the things.
Any help would be highly appreciated.
Error Message:
{\"Status\":{\"facebook\":{\"status\":403,\"info\":\"Forbidden:
\"}},\"URIs\":[]}
UPDATE
Below is the json I get when I run me/permissions in facebook graph API explorer:
{
"data": [
{
"permission": "user_birthday",
"status": "granted"
},
{
"permission": "user_about_me",
"status": "granted"
},
{
"permission": "user_status",
"status": "granted"
},
{
"permission": "user_posts",
"status": "granted"
},
{
"permission": "email",
"status": "granted"
},
{
"permission": "manage_pages",
"status": "granted"
},
{
"permission": "publish_actions",
"status": "granted"
},
{
"permission": "public_profile",
"status": "granted"
}
]
}
I have resolved this problem:
public function facebookSharing($access_token) {
$app = new UEApp(env('UNIFICATION_APP_KEY'), env('UNIFICATION_APP_SECRATE'));
$user = new UEUser('unification_userkey', 'unification_usersecret');
$connection = $user->add_connection('FACEBOOK', "facebook", $access_token);
$options = array(
"receivers" => array(
array(
"name"=> "Me"
)
),
"message"=>array(
"subject"=>'testing',
"body"=> 'description',
"image"=> 'use any image url',
"link"=>array(
"uri"=> 'any web site url',
"description"=> "",
"title"=>"Title"
)
)
);
$uris = $connection->send_message($options);
}
Please use your keys like
facebook accesstoken
UNIFICATION_APP_KEY (its your unification keys)
UNIFICATION_APP_SECRATE (its your unification keys)
If this will not work then please let me know.
Can you please confirm if the "Connector" name that you have given is correct?
While I tried your sample code that you provided, I could sent the message to facebook via UE.
Can you please provide the exact error message that is returned while you execute the command?

Create link with "#" symbol in facebook status with facebook api

I have problem with facebook api and can't find any information.
I want create link (example #Username) in status, with Graph API.
My code:
$response = $facebook->api("/" . $data['pageId'] . "/feed", 'POST',
[
'message' => $messageContainer['message'],
'link' => 'https://example.com/reviews',
'name' => $messageContainer['subject'],
'description' => $messageContainer['description'],
'picture' => 'https://example.com/uploads/dealer/' . $messageContainer['logo'],
]
);
$messageContainer['message'] = 'Some text #Username';
but text wasn't created as link in status only as string.
May be it's impossible?

Post a picture fia Facebook API

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}',
)
);

facebook post article with user token

Hello i'm trying to post on a user's wall a big foto article like this one
I have tried this code
$post = array(
'access_token' => $row['user_token'],
'message' => 'Hello world ',
'link' => $row['url'],
//'name' => "This is my title",
//'caption' => "My Caption",
//'description' => "Some Description...",
'picture' => $imgurl
//'image' => $row['img']
);
$res = $facebook->api("/" . $row['facebook_id']. "/feed", 'POST', $post);
and it produces a small picture like this one
And this code produces nothing
/* make the API call */
$response = $facebook->api(
"/me/objects/article",//or /$user_id/objects/article
"POST",
array (
'fb:app_id' => '302184056577324',//change with stuff
'og:type' => 'article',
'og:url' => 'Put your own URL to the object here',
'og:title' => 'Sample Article',
'og:image' => 'https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png',
)
);
/* handle the result */
Can someone provide working code or explain like you would to a 7 years old ?
If you want the image to be displayed at the larger size, the source image has to be at least 1200x630px as described at https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content#images and already pointed out by CBroe...

How to post on a facebook application user's facebook feed using cURL?

I have made a snake game using javascript and HTML5 Canvas element. It can be found at apps.facebook.com/snaqe_game. I have attained permissions and authorized the app for publish_feed or something using the Facebook Developer Documentation but the problem I am facing is while posting the player's score on his wall.
Please Note:
I do not have the PHP SDK
Please See: apps.facebook.com/mg-copter
Update Facebook News Feed using the Graph API in PHP
$data = array();
$data['post'] = array(
'access_token' => $access_token,
'message' => 'this is the message',
'picture' => 'http://sudocode.net/wp-content/uploads/2011/01/developer.facebook.com_banner-150x150.png',
'link' => 'http://sudocode.net/article/313/how-to-register-a-new-facebook-application/',
'name' => 'How to Register a New Facebook Application',
'caption' => 'sudocode | it looks like it works',
'description' => 'Here are some notes on how to register a new Facebook application.',
'actions' => '{"name": "Read the Article", "link": "http://sudocode.net/article/313/how-to-register-a-new-facebook-application/"}',
);
$response = xhttp::fetch("https://graph.facebook.com/{$profile_id}/feed", $data);

Categories