Post in the wall of a Facebook user - php

My question is very simple and has been answered lots of times in Stackoverflow but in order to the changing of the Facebook API I want to make certain if a user who is using my app can post to their wall a message generated automatically by the app.
If the user is reading in my app a comment he/she likes, I want he/she can post to their wall a message like "I've been reading a very interesting comment about..." and I would like that tis text appears automatically in the window where Facebook requests permission to the user to post in their wall.
I've tried the JS API with "feed" method but the text in the field message is ignored. I'm going to try with PHP API but I think the result will be the same.
Thanks in advance!!

JavaScript SDK
You can send the following values using the JavaScript SDK:
// calling the API ...
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
(code and image taken from the docs)
I described, what field is what text in the popup.
If not provided, name, image, caption and description are derived from the webpage, given in the link.
You cannot include a default message in the JS popup.
PHP SDK
If you are using the PHP SDK, you can however include a message.
Code example:
try {
$facebook->api(
"/{$facebookId}/feed",
"POST",
array(
// this is the important part
'message' => "This is your message!",
'link' => $yourLink,
'name' => "This is your name",
'caption' => '..',
'description' => '...',
'type' => 'link',
'application' => array(
'name' => 'Name of your app',
'id' => $idOfYourApp
)
)
);
}
catch (\FacebookApiException $exception)
{
// ...
}

the "message" field in feed no longer works. You have to use "description" or "caption"
This is because Facebook mentioned something along the lines of "A user should be able to say what they want about content on the internet".

Related

Posting Message using Facebook API

Couldn't find this anywhere on Stack overflow, I just don't know what to do.
I just want to place a message on my community Facebook page using the Facebook PHP API, where to get started?
Example:
I click a button on my website, which then automatically posts 'I clicked the button' on my Facebook (community) page.
Thanks in advance!
There is documentation for what you need.
$session, 'POST', '/me/feed', array(
'link' => 'www.example.com',
'message' => 'User provided message'
)
Change /me/feed to the page you want.

How can I add information about read article on my site to facebook RECENT ACTIVITY?

How can I add information about read article on my site to facebook RECENT ACTIVITY (like the Guardian)?
I use php and code:
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'example.com',
'message' => 'Test message'
));
This code posting the message in user's timeline but I want to post message in his recent activity.
probably you wan't to use open graph api, not graph api
https://developers.facebook.com/docs/opengraph/
https://developers.facebook.com/docs/opengraph/tutorial/
https://developers.facebook.com/docs/opengraph/opengraph-approval/

Using graph API and creating a link on the event page

I must be missing something really obvious.
I have created successfully an Event with the graph API
I now want to put a link on the event page
When i use the code below, it creates a message but not a link. So please someone what am i missing. I do get a linkid back as well as you can see the message on the page.
So this is the pretty simple code.
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'fileUpload' => true
));
$fb->setAccessToken($_SESSION[ $eid.'_FB_USER_ACCESSCODE' ]);
$data = array( 'access_token' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'link' => 'http://www.thedomain.com',
'message' => "To purchase your tickets"
);
$result = $fb->api($newFBEventId."/feed","post",$data);
Thanks
This is a Bug and its reported and marked as confidential
With the below text and its also contain security hole
bug report link
Below is my bug report text.
Other details on this report are shown to Facebook employees only
I recently attempted to post on an event's wall using the Graph API, but only the message is posted; Everything else is not showing. e.g.
Link
Picture
etc
There is one more big thing that the post doesn't show; That this post is post "via a Facebook app"
Note: posting on a page or user wall worked and also normal messages posted on an event 's wall.
The most important thing is when the post is shown on the event's wall "it does not show that its posted by a Facebook Application".
This is very dangerous; For example I can make an application and post nonsense on a user's event wall. People will think that this is posted by the user.
Thanks

posting on a friend's wall using graph API

Posting a message on friend's wall, graph API.
i have the publish_stream extended permission of the user, who is using the application.
the code workds if i want to post sth on my wall.
is there any method to post on wall or send message to all the friends of a particular user??
please help thanks!!
following is the code, but it is not working.
$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend){
$friendsUserId = $friend['id'];
echo $friendsUserId . "</br>";
$result = $facebook->api('/$friendsUserId/feed', 'POST', array(
message' => 'Test Message' ));
print_r($result);
}
This would perhaps be the way to do it.. (Untested, but I use something similar for my app.)
$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend) {
$facebook->api('/$friend['id']/feed', 'post', array(
'message' => 'just a test message',
'link' => 'http://site.com',
'name' => 'just a test name',
'caption' => 'just a test caption',
'description' => 'just a test description',
));
}
This is using the PHP API.
I just did a little testing, and having the permissions of the user, I could indeed post on the user's friends walls via the php api:
$facebook->api('/[FRIEND_ID]/feed', 'post', array(
'message' => 'test message',
'link' => 'http://google.com',
'name' => 'test name',
'caption' => 'test caption',
'description' => 'test long description',
));
The publish_stream permission only allows you to publish content on that particular users wall - you cannot post on the wall of all his friends.
Think about it this way - say you have not authorized an application to post anything on your facebook wall but just because one of your friends has given access to his wall - it automatically does not give the application access to publish on the wall of all his friends.
EDIT
Rahul, I tried yesterday night to login as myself and post a message on the wall of one of my friends through my app and surprisingly it worked. I was under the wrong impression that you could not do that. My apologies.
But I'm still not able to figure this out. Let me explain
1) I have my real facebook lets call it abc and a test facebook account xyz which I've added as my friend to abc
2) I login into my app using my abc faceboook account and publish a message on the wall of my friend xyz
3) Now I login to facebook.com as abc and it shows on my news feed the message that I published on xyz's wall. When I click on xyz's profile - the message shows up on his wall too. So far so good
4) Now I log out of facebook.com as abc and log back in as xyz. But now I dont see the message that was posted through the app on the wall of xyz.
I dont know if there is any kind of delay but I've waited 30 mins but still its not there. But it continues to show when I log in as abc.
I hope you understand what I'm trying to convey here.
I've used the same piece of code like yours - so can you try the above scenarios and see if you experience something similar
Thanks
Gubloo's answer is close.
Posting to a friend's wall is completely possible, but with one caveat, said friend must have also gone through the 'Permissions' dialogue at some point. Meaning, users of your application will be able to post to the wall's of other users of your application.
I'm going to give you the iPhone code, because I don't know php and imagine you'll get the gist. Just replace 'me' with the UID of whatever you are trying to post to, be a page, or a Friend's profile.
[_facebook requestWithGraphPath:#"/me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
I'm actually curious to know if this would give the user the ability to post on the wall of anyone who uses the application, and not just his friends.
$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend) {
$facebook->api('/$friend['id']/feed', 'post', array(
'message' => 'just a test message',
'link' => 'sample link.com',
'name' => 'just a test name',
'caption' => 'just a test caption',
'description' => 'just a test description',
));
}
Above code work for me tooooo
Thanks for the post

how send message facebook friend through graph api using Accessstoken

Can anyone help me to send message to facebook friends using graph api.
I tried
$response = $facebook->call_api("/me/feed", "post", "to=john","message=You have a Test message");
It's not working.
I have the accesstoken of the user in my hand.only I am confused on sending process.
You can't send messages using a Facebook application. You used to be able to do that, but the (predictable?) colossal amount of abuse led to the revocation of this ability.
Provided Alice, your user, has given you the necessary extended permissions, you have the following options:
Post to Alice's wall on her behalf
Send email to Alice
Create events on behalf of Alice
invite Bob (not your user) to said events
Issue a request/invitation on behalf of Alice to Bob
Issue a request from the App to Alice
You could open the Send Dialog in a popup.
$parameters = array(
'app_id' => $facebook->getAppId(),
'to' => $facebookUserId,
'link' => 'http://google.nl/',
'redirect_uri' => 'http://my.app.url/callback'
);
$url = 'http://www.facebook.com/dialog/send?'.http_build_query($parameters);
echo '<script type="text/javascript">window.open('.json_encode($url).', ...
For detailed options see:
https://developers.facebook.com/docs/reference/dialogs/send/
$attachment = array(
'access_token' => $access_token,
'message' => $msg,
'name' => $name,
'link' => $link,
'description' => $desc,
);
facebook->api('/'.$uesr_id.'/feed', 'POST', $attachment);
Technically you can do feed or cross feed post with privacy settings that allows only the feed owner to see the post but its not really sending a message to a person.
You can use
HTTP POST with
PATH
https://graph.facebook.com/friend_facebook_id/feed
PARAMETER
MESSAGE = your message
ACCESS_TOKEN = your oauth2 access token
You can send to their facebook email. Facebook email is consisting profile nickname+'#facebook.com'. The email will goes to their facebook inbox message. Note that facebook email does not accept spoofing email. You will need whitelabel domain or use SendGrid.
You will need to integrate xmpp chat to reply a message and to write a new message.
I saw this post and noticed it was not right. Using the javascriot api you can post to a friend's feed like so:
In this example "friendID" is the FB user ID of the friend.
This api call requires the "publish_stream" permission.
FB.api('/'+friendID+'/feed', 'post',
{
method: 'feed',
message: messageText,
name: 'write a title here',
caption: 'Put a caption here.',
description: 'Put your description here.',
link: 'http://stackoverflow.com/questions/2943297/how-send-message-facebook-friend-through-graph-api-using-accessstoken',
picture: 'link to the preview thumbnail',
},
function(response) {
if (!response || response.error) {
//alert('Error occured');
} else {
//alert('Post ID: ' + response.id);
}
});
So this does it with the javasfcript SDK- the PHP method must be similar.
Instead of using the below code
[facebook dialog:#"feed"
andParams:params
andDelegate:self];
Use the following solution
[facebook requestWithGraphPath:#"me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];

Categories