facebook PHP SDK posting as activity, not post - php

I hope you will be able to help me.
I'm developing an app, and I'm willing to post an activity (that appears on user timeline in recent activity) everytime the user use my application.
Although, for the moment, I have this code below, and it only posts a normal link :
if($can_post){
$facebook->api('/'.$uid.'/feed', 'post', array(
'message' => '',
'name' => 'Name',
'caption' => 'Caption',
'description' => 'SDesc',
'picture' => 'picture url',
'link' => 'link',
'actions' => array(array('name' => 'catch phrase',
'link' => 'http://link'))
));

Check out this guide on posting "stories" to the user's timeline using the Open Graph API, so maybe it's this functionality that you need. The example they give is just a like, but it can be easily modified.
Be aware that Facebook will have to approve you app again if you want to use stories (see end of page on link above).
It's also worth noting that Facebook have also defined a wide range of predefined "Actions" to help in the process, so it's a good idea to check to see if your app falls into one of these categories.

Related

Empty story clicks statistics in Facebook application insights

Posting stories via php facebook application using such construction :
$facebook->api('/'.$wall_id.'/feed',
'post',
array(
'access_token' => $access_token,
'message' => $message,
'picture' => $picture,
'caption' => $caption,
'link' => $link
)
);
There are "702 Stories Published" in app insights ( Apps->My application->Insights->Stream Publish ). But there are no Story Impressions or Story Clicks at all. (702 - 0 - 0)
Is it a bug, or do I need to pass some additional parameters to FB api to track these clicks?
How much time has passed since the stories have been first posted? Facebook Insights requires at least three days to update its data.
Let's wait, and we'll see if this is a bug. I don't know about any special parameter to enable tracking: it should be available without any configuration.

how to add share action to the post in facebook?

i'm using this code to post to my application wall
$attachment = array('message' => 'xxxxxxxxxxxxxxxx...',
'name' => 'xxxxxxxxxxxxxxxxxxx',
'caption' => 'xxxxxxxxxxxxxxxxxx',
'link' => 'xxxxxxxxxxxxxxxxxx',
'description' => 'xxxxxxxxxxxxxxxxxx',
'picture' => 'xxxxxxxxxxxxxxxxxx',
'actions' => array(array('name' => 'Download!',
'link' => 'xxxxxxxxxxxxxxxxxx'))
);
$result = $facebook->api('/2222222222222/feed/','post',$attachment);
when i post to my application wall manually the post is appearing on the application users wall with the share action
but when i use the above code it only appear on the app wall with like and comment actions only.
why?
and how to add the share action to the actions array?
i didn't find any answer online, but i just found the solution to my problem by chance
i removed the action parameter from the attachment.
but if there is a link parameter in the attachment the share action won't appear so you will have to give up the link parameter.
the proper names for the action link is:
array( array('text' => 'Download!', 'href' => 'xxxxxxxxxxxxxxx'));
Keep in mind that you can't use action links in the graph api (yet). so this functionality is limited to the REST api.
Let me know if this helps
http://facebookanswers.co.uk/?p=270
This article explains it. The key is this:
'actions' => array('name'=>'Sweet FA','link'=>'http://www.facebookanswers.co.uk'),
This is fine for adding one action. However, I'm not sure how to add two.
Hi the solution is here
instead of
$result = $facebook->api('/2222222222222/feed/','post',$attachment);
use
$result = $facebook->api('/2222222222222/links/','post',$attachment);
i'm still facing one little problem with the picture not showing after this change, if i come to a solution to it I'll come back here and post it.

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

Using the Facebook PHP SDK to post from Group

I'd like to use the Facebook PHP SDK to post on a user's wall FROM a group (i.e. not as a Status Update, from the user via an external app, but from a group via an external app). I'm having a difficult time finding docs on the topic, and would like a code example as well as any information regarding any restrictions (e.g. can a group post on one's wall if the user does not belong to the group).
I've tried using the 'from' parameter, like this:
$attachment = array(
'access_token' => $access_token,
'message' => "Message from the group",
'name' => "Name of the Post",
'from' => array(
'name' => "Sender's Name",
'id' => "#############"
),
'link' => "http://myurl.com/",
'description' => "Description of the Posting",
'picture'=>"http://myurl.com/mylogo.png",
);
$ret_code=$facebook->api('/'.$fb_id.'/feed', 'POST', $attachment);
While posting as a "Page" is totally possible by getting a page access_token, I've never seen anything similar for Facebook groups. So I would assume that this is NOT possible.

Facebook Graph API: How to add vote links to a wall post?

I am building a Facebook app with voting included. With it I want to send a message to the user's wall including some text and two or more links.
I also want to control the link text so that I can get links like "Yes" and "No".
The first thing I tried was posting regular -tags, but (no surprise) that didn't work. I have seen other apps do this though. Are there any special tags that allow links?
Thank you.
I'll assume that you're using the Graph API and already have publish a post working.
I think the properties property might be what you are looking for (it is left out of the new API reference but is described here). This allows links although they might not be formatted quite how you want. Example:
$data = array (
'name' => ...,
'link' => ...,
'properties' => array (
'Yes' => array (
'text' => 'Vote',
'href' => 'http://www.example.com?vote=yes'
),
'No' => array (
'text' => 'Vote',
'href' => 'http://www.example.com?vote=no'
)
),
); //And whatever other properties you want
$facebook->api('/uid/feed', 'POST', $data);
The properties will appear after beneath description in the post and come out like the following:
Yes: Vote

Categories