14

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
  • Q1:これはjavascriptまたはphpですか?
  • Q2:「curl-F」関数の参照がどこにも表示されません。誰かplsが表示できますか?

どうもありがとう〜

4

1 に答える 1

14

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."
});
于 2012-04-16T19:06:19.320 に答える