0
FacebookのAPIには本当に苦労しています。 Aはアプリケーション、オブジェクト、アクションを作成してストリームに公開することをテストしたいと思います(パブリックパブリッシングはFacebookの承認を得なければなりませんが、私のアプリの管理者としてテストすることが許可されています)。しかし、それは悪くない。ここではスクリプトは次のとおりです。JS APIを使用したFacebook APIの公開
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# mehdientest:http://ogp.me/ns/fb/mehdientest#">
<title>OG Tutorial App</title>
<meta property="fb:app_id" content="312683425452812" />
<meta property="og:type" content="mehdientest:Campain" />
<meta property="og:url" content="http://www.example.com/pumpkinpie.html" />
<meta property="og:title" content="Sample Campain" />
<meta property="og:description" content="Some Arbitrary String" />
<meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" />
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '312683425452812', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
FB.Event.subscribe('auth.login', function(response) {
// do something with response
login();
});
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
login();
}
});
function login() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
}
function publish() {
FB.api('/me/mehdientest:Create?Campain=http://www.example.com/pumpkinpie.html', 'post', function(response) {
if (!response || response.error) {
alert('msg');
}
});
}
function logout(){
FB.logout(function(response){});
}
</script>
<h3>Example</h3>
<p>
<img title="Example" src="" width="550"/>
<input type="button" value="Logout" onclick="logout();"></input>
<input type="button" value="Login" onclick="login();"></input>
<input type="button" value="Publish" onclick="publish();"></input>
<div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
</p>
</body>
</html>
私も頭領域にパブリッシュ()関数を呼び出ししようとしましたが、これも動作しません。
誰かがアイデアを持っていますか?
ベスト、「それは動作しません」と言っ Newben
こんにちは、ありがとうございました。実際、それはまだ機能しませんでした。私はfb.api呼び出しのエラーメッセージを次のように変更しました:if(!response || response.error){alert(response.error.message);したがって、私が得たメッセージは次のとおりです。「参照オブジェクトを指定していないため、公開しようとしているアクションは無効です。少なくとも次のいずれかのプロパティを指定する必要があります。しかし、私のアプリのダッシュボードでは、オブジェクトとアクションを指定し、オブジェクトにアクションをターゲット設定しました。私はそれが間違っていることを本当に知っていません... – Newben
あなたが提出した動詞(Create)と名詞(Campain)は大文字で表記されていますか?あなたが投稿したエラーメッセージは、それが予期していることを示しているためです:campain。 FacebookのAPIのすべてで大文字と小文字が区別されます。 –
実際、私はそれらを大文字で提出しました。しかし、小文字に変更しました。そして、エラーメッセージが "(#3502)URL http://www.example.com/pumpkinpie.htmlのオブジェクトに"ウェブサイト "のog:タイプを持っています。プロパティ 'campain'にはog:typeのオブジェクトが必要です'mehdientest:campain'。 "それは何か意味ですか? – Newben