Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API - What is " curl -F "?

Tags:

curl

facebook

api

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
  • Q1: is this a javascript or php ?
  • Q2: I don't see "curl -F" function reference nowhere, can someone pls show me one ?

Many thanks ~

like image 298
Ray C Lin Avatar asked Apr 16 '12 19:04

Ray C Lin


People also ask

What is F in curl request?

-F tells curl to emulate a filled in HTML Form that has just had it's submit button clicked.

What does curl do in API?

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.

What is REST API curl?

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.

What is curl request D?

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.


1 Answers

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."
});
like image 132
Jeff B Avatar answered Sep 28 '22 22:09

Jeff B