Create a note with Facebook connect - facebook

I am wondering if it is possible to create a note on facebook through my website using facebook connect. I have notes on my website and I essentially want the ability to be able to push them over to the user's facebook account.

I'm not sure - I don't think you actually can.
The reference doesn't have a section on publishing (say, compared to the same page for photos)
However, this is a user_notes extended permission, so perhaps it's possible just not documented? Or it could just be that notes are, indeed, read-only.

As for now, the 'create' part is missing from documentation but after some experimentation it works like this with the graph api based php-sdk:
public function postNote ($title, $content) {
$note_details = array(
'subject'=> $title,
'message'=> $content,
);
$result = $this->facebook->api('/me/notes', 'post', $note_details);
}
publish_stream permission is required

Related

Facebook Graph API - Access token for page likes, name and url

I'm trying to update some old PHP code which is supposed to get the name, likes and a link to the given Facebook page. This is the current old code:
$fbsite1 = json_decode(file_get_contents('http://graph.facebook.com/page1'));
$fbsite2 = json_decode(file_get_contents('http://graph.facebook.com/page2'));
$fbsite3 = json_decode(file_get_contents('https://graph.facebook.com/page3'));
for($j=1; $j<=3; $j++){
$data[] = array(
'name' => ${'fbsite'.$j}->name,
'likes' => ${'fbsite'.$j}->likes,
'link' => ${'fbsite'.$j}->link
);
}
The problem is that this method requires an access token, which I'm not quite sure how to get. I've looked at the Facebook API reference, but there seems to be a few different access tokens (different permission etc.). Which one do I need to accomplish this? How do I get it?
If the pages are public, then you only need an app access token.
So create an app in the FB dev section (if you have not done so already), and then include your app access token in those request URLs:
http://graph.facebook.com/page1?access_token=…
FYI, you should consider requesting all that data in one go, instead of making multiple API requests. You can do that using this syntax (for up to 50 ids in one request),
http://graph.facebook.com/?ids=page1,page2,page3&access_token=…
And you will have to explicitly ask for the name, link and likes fields now (otherwise you will get name and id only):
http://graph.facebook.com/?ids=page1,page2,page3&fields=name,likes,link&access_token=…

FB Api: Tag/mention another page on my own fan page

I have a fan page which I am an admin of. I'd like to create a simple button - when I click it, it would create a post on my Fanpage, with a predefined a message and a photo. I have been able to achieve this fairly simple using the Graph API:
$args = array(
'access_token' => <my_acc_token>,
'url' => <url_of_image>,
'message' => <my_message>
);
try{
$facebook->api('/<id_of_my_page>/photos', 'POST', $args);
}catch(Exception $o ){
print_r($o);
}
ISSUE:
I would like to now be able to also Tag or Mention another page in that post, but nothing seems to work!
I tried adding a #[user-id-of-page] into the message property or my $args array - but to no avail.
Is tagging/mentioning even possible without having to use Facebook actions? How can this be achieved?
https://developers.facebook.com/docs/opengraph/using-actions#pages
Be aware that you have to go through the review process with this, else you can only mention your own Pages.
So in order to mention other Pages, you would need to get the permissions manage_pages and publish_actions approved, and you need to get the "Page Mentions" feature approved. Go to "Status & Review" in your App settings and click on "Start a Submission". Scroll down in the list on the left and you will find "Page Mentions".

how many posts can i post on user walls on facebook via app & SDK

I want to make php script using the faceook graph and sdk to make a time-crom task that post evey 6 hours specific status on all users walls
my question is how many users can i send to them at once ?
may be 1000 or 50000 or what?
i'm using
$attachment = array(
'access_token'=>TOKEN,
'message'=>'message_here',
'link' => 'http://www.example.com',
);
$result = $facebook->api(
'me/links',
'post',
$attachment
);
I think there is no official limit, but your App will get restricted very soon if you do this. Also, it is against several Facebook rules. First, because it is spammy. Second, because you are only allowed to fill the "message" field user generated text. Also, "all user walls" means that you would need the permission offline_access, which is deprecated and will be removed soon, luckily. Else, an access token is valid for only 2 hours and you can only extend it to 60 days. For each user wall, you need the user access token of that user, of course.

Facebook Graph API Group Files

Facebook offers a new functionality for groups. Now it is possible to post also files within a group. (http://mashable.com/2012/05/10/facebook-groups-3/)
I am trying to query now the files using the Graph API but on the documentation site there are only 4 urls described. "docs", "members", "feed", "picture".
When I read the "feed" path I will not get file postings.
Is there a hidden path? I also found no new permission.
Anyone has any idea?
I have searched for a solution on several internet pages but there are only descriptions on how to read and post photos, which is described in the document.
Is there nobody writing an app where you can upload files to groups?
try this, this might be helpful for you
try {
$facebook->api('/'.$groups[$id].'/feed', 'POST',
array(
'access_token' => $access_token,
'message' => stripslashes(stripslashes($mapp_message)),
'name' => stripslashes($name),
'link' => $link,
'description' => stripslashes(stripslashes($description)),
'picture' => "images/send_imges/".$image
)
);
} catch(FacebookApiException $e) {
echo $e;
}
The Graph API documentation for Groups mentions a way to retrieve the documents from a group. If you click the docs connection in the document, it'll take you to the Graph API Explorer, where you can test your sample queries. So, basically, all you need to do to obtain the document uploaded to a group is perform a request to the following url with a valid Access Token (with no special permission):
https://graph.facebook.com/groupId/docs
Or, if you want to access a specific doc, you need the document_id for that particular doc. So you can simply request the following URL with a valid Access Token:
https://graph.facebook.com/docsId
The instructions on posting a doc and its related permissions have been discussed in this answer. I'm not very sure whether it works or not as I have not tested the method. But I'm pretty sure that you can read the details by making an API call to the urls mentioned above.

Using 'from' to post a facebook message as App name

I have an Facebook App that is currently posting to a WALL. All the posting are being Titled as MY post. I would like it to be titled by the App. In this documentation, it says there is a 'from' parameter. I've tried to use it a couple of ways and both ways have been unsuccessful. Does anyone have a clue?
https://developers.facebook.com/docs/reference/dialogs/feed/
$attachment = array('message' => $message,
'from' => "<APP_ID>",
//'from' => array('name' => "Sender's Name",'id' => "<APP_ID>"),
}
$me = $this->facebook->api('/me/feed/', 'POST', $attachment);
The from property MUST be a user or a page. You could possibly create a Facebook page with the name of your application and use that.
I've never used the FROM parameter in the Graph API, just on the legacy REST API. And that API parameter was actually actor_id instead of FROM.
Obviously this doesn't solve your problem. To solve your problem, get the access_token for your page from the /me/accounts Graph API end point. When you use this access token, you are identified as the account for which it corresponds, and when you post to /{page_id}/feed with it, it will be posted as the page and in turn be published out to all your users.
<script type="text/javascript">
FB.api("/123123123/feed", "post", {
message: "Test!",
access_token: '184484190795|SDlfkjweifljasdf.3600.123123123.1-2342342|234234234234|XLjsldfjLISJflwieab'
},
function(response)
{
console.log(response);
});
</script>
Thank you all for the suggestions. I finally was able to solve the problem by combining these 2 articles. The basic steps of the first article is still valid. But it is written in the old API. The second article help be get through the step the new REST api couldn't do. Hope this helps.
http://www.emcro.com/blog/2009/01/facebook-infinite-session-keys-no-more/
http://www.alyssapowell.com/2010/10/how-to-generate-an-infinite-session-key-in-facebook/