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

问题描述

从Facebook图形API(https://developers.facebook.com/docs/reference/api/):

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 - 什么是"卷曲-F"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:34