Facebook API - 什么是"curl -F " [英] Facebook API - What is " curl -F "?
问题描述
来自 Facebook Graph Api (https://developers.facebook.com/docs/reference/api/) :
From Facebook Graph Api (https://developers.facebook.com/docs/reference/api/) :
发布:您可以通过向适当的连接 URL 发出 HTTP POST 请求,使用访问权限发布到 Facebook 图令牌.例如,您可以通过以下方式在 Arjun 的墙上发布新的墙贴向 https://graph.facebook.com/arjun/feed 发出 POST 请求:>
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:这是 javascript 还是 php?
- Q2:我没有看到curl -F"函数参考无处,有人可以给我看看吗?
非常感谢~
推荐答案
curl
(或 cURL
)是一个用于访问 URL 的命令行工具.
curl
(or cURL
) is a command-line tool for accessing URLs.
文档:http://curl.haxx.se/docs/manpage.html
在此示例中,他们只是向 https://graph.facebook.com/arjun/feed
发送 POST.-F
定义了与 POST 一起提交的参数.
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.
这不是 javascript 或 php.您可以在 php 中使用 curl,尽管任何带有这些参数的 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.
要在 JavaScript 中执行此操作,您需要创建一个表单然后提交:
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();
使用 jQuery,简单很多:
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."
});
这篇关于Facebook API - 什么是"curl -F "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!