来自 Facebook 图形 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:这是 javascript 还是 php?
- Q2:我没有看到“curl -F” 函数引用无处可寻,谁能告诉我一个?
非常感谢~
最佳答案
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();
使用jQuery,就简单多了:
$.post("https://graph.facebook.com/arjun/feed", {
access_token: token,
message: "Hello, Arjun. I like this new API."
});
关于Facebook API - 什么是 "curl -F "?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10180029/