From Facebook Graph Api (https://developers.facebook.com/docs/reference/api/) :
Publishing: You can publish to the Facebook graph by issuing HTTP POST requests to the appropriate connection URLs, using an access token. For example, you can post a new wall post on Arjun's wall by issuing a POST request to https://graph.facebook.com/arjun/feed:
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
Many thanks ~
-F tells curl to emulate a filled in HTML Form that has just had it's submit button clicked.
cURL, which stands for client URL, is a command line tool that developers use to transfer data to and from a server. At the most fundamental, cURL lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send.
This tutorial gives a brief overview of testing a REST API using curl. curl is a command-line tool for transferring data, and it supports about 22 protocols, including HTTP. This combination makes it a very good ad-hoc tool for testing our REST services.
The -d or --data option makes the curl command send data in POST request to the server. This option makes the curl command pass data to the server using content-type (JSON in your case) just as the browser does when a user submits a form.
curl
(or cURL
) is a command-line tool for accessing URLs.
Documentation: http://curl.haxx.se/docs/manpage.html
In this example, they are simply sending a POST to https://graph.facebook.com/arjun/feed
. The -F
is defining parameters to be submitted with the POST.
This is not javascript or php. You can use curl in php, although any POST to that address with those parameters will accomplish what the example is demonstrating.
To do this in javascript, you would create a form and then submit it:
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "https://graph.facebook.com/arjun/feed");
var tokenField = document.createElement("input");
tokenField.setAttribute("type", "hidden");
tokenField.setAttribute("name", "access_token");
tokenField.setAttribute("value", token);
var msgField = document.createElement("input");
msgField.setAttribute("type", "hidden");
msgField.setAttribute("name", "message");
msgField.setAttribute("value", "Hello, Arjun. I like this new API.");
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
Using jQuery, it's a lot simpler:
$.post("https://graph.facebook.com/arjun/feed", {
access_token: token,
message: "Hello, Arjun. I like this new API."
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With