use*_*899 2 javascript java jquery facebook facebook-graph-api
如何通过Open Graph标签朋友使用facebook api taggable_friends.我的应用程序使用taggable_friends api我想在朋友墙上标记我的朋友.使用提及朋友或标记朋友 https://developers.facebook.com/docs/opengraph/using-actions/v2.0#capabilities
我使用Open Graph doc Step by Step尝试但是给我"你,或者这个应用程序的Open Graph Test用户,必须至少发布过一次这个动作"如何设置?
小智 9
在FB javascript sdk上,
- *fb dashboard - > Open Graph
- *在你的js
1.拨打js sdk
window.fbAsyncInit = function() {
FB.init({
appId : {YOUR_APP_ID} , // App ID
version: 'v2.0',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(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/sdk.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
}
Run Code Online (Sandbox Code Playgroud)
3.登录FB询问这些范围
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
console.log(response.authResponse); // Get User Information.
} else
{
console.log('Authorization failed.');
}
},{scope: 'user_friends, publish_actions, status_update, read_stream, manage_friendlists'});// ' user_interests, user_likes, etc.. '
}
Run Code Online (Sandbox Code Playgroud)
4.使用以下函数获取已记录的用户taggable_friends:
var var friendsIDarray = [];
var user_friend_list;
function meTaggableFriends(){
FB.api(
"/me/taggable_friends",
function (response) {
if (response && !response.error) {
/* handle the result */
console.log(response)
for(var i=0; i<response.data.length; i++){
var data = response.data;
friendsIDarray.push(data[i].id);
}
user_friend_list = friendsIDarray.join();
}
}
);
Run Code Online (Sandbox Code Playgroud)
5.现在,我们已经在user_friend_list中为我们想要在帖子中标记的朋友存储了令牌ID,我们可以使用这样的Open Graph操作来标记朋友:
FB.api(
'me/{namespace}:{action}',
'post',
{
{object-type}:'http://example.com/object/', // make sure to have the apropiate og:type meta set
place:'https://example.com/place/', // open graph page with metas for location, id for a location page etc
tags: user_friend_list, // the tokens ids for those friens you wanna tag and you got on previous step
title: 'whatever',
message: 'like this, you tag friends @['+ONE_TOKEN_ID_FROM_TAGGABLE_FRIENDS+'] , @['+ONE_TOKEN_ID_FROM_TAGGABLE_FRIENDS+'] etc'
},
function(response) {
console.log(response)
}
);
Run Code Online (Sandbox Code Playgroud)
你可以在上面找到更多相关信息:
https://developers.facebook.com/docs/opengraph/using-actions/v2.1
希望你觉得它有用.
| 归档时间: |
|
| 查看次数: |
8373 次 |
| 最近记录: |