Facebook API - 什么是“ curl -F“? [英] Facebook API - What is " curl -F "?

查看:268
本文介绍了Facebook API - 什么是“ curl -F“?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


发布:您可以通过向适当的连接URL发出HTTP POST请求,使用访问
令牌。例如,您可以通过
在Arjun的墙上发布新的墙帖子,向POST请求发送 https: //graph.facebook.com/arjun/feed




  curl  - F'access_token = ...'\ 
-F'message =你好,Arjun。我喜欢这个新的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。我喜欢这个新的API。

form.appendChild(hiddenField);

document.body.appendChild(form);
form.submit();

使用jQuery更简单:

  $。post(https://graph.facebook.com/arjun/feed,{
access_token:token,
message:Hello,Arjun 。我喜欢这个新的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 ~

解决方案

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."
});

这篇关于Facebook API - 什么是“ curl -F“?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆