Facebook API - 什么是"curl -F"?

Ray*_*Lin 8 api curl facebook

来自Facebook Graph Api(https://developers.facebook.com/docs/reference/api/):

发布:您可以使用访问令牌通过向相应的连接URL发出HTTP POST请求来发布到Facebook图形.例如,您可以通过向https://graph.facebook.com/arjun/feed发出POST请求,在Arjun的墙上发布新的墙贴:

curl -F 'access_token=...' \
     -F 'message=Hello, Arjun. I like this new API.' \
     https://graph.facebook.com/arjun/feed
Run Code Online (Sandbox Code Playgroud)
  • Q1:这是一个javascript还是php?
  • Q2:我没有看到"卷曲-F"功能参考,有人可以给我看一个吗?

非常感谢〜

Jef*_*f B 12

curl(或cURL)是用于访问URL的命令行工具.

文档:http://curl.haxx.se/docs/manpage.html

在这个例子中,他们只是发送一个POST https://graph.facebook.com/arjun/feed.该-F被定义参数与POST提交.

这不是javascript或php.您可以在php中使用curl,尽管使用这些参数对该地址的任何POST都将完成示例演示的内容.

要在javascript中执行此操作,您需要创建一个表单然后提交它:

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();
Run Code Online (Sandbox Code Playgroud)

使用jQuery,它更简单:

$.post("https://graph.facebook.com/arjun/feed", { 
    access_token: token, 
    message: "Hello, Arjun. I like this new API."
});
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢你,我的工作几乎都是以你的榜样完成的! (2认同)