如何在用户有权访问应用程序时从 Graph API 获取应用程序数据
How to get App data from Graph API when user has access to the app
我想知道当用户有权访问我的应用程序数据(标题和描述)并使用用户区域设置获取本地化值时我如何访问它。
我的代码是这样的:
var imageUrl = "http://mysite.test/webroot/img/test_image.jpg",
userID = response.authResponse.userID,
userLanguage,
appTitle,
appDescription;
if (response.status === 'connected') {
FB.api(
"/" + userID,
function (response) {
if (response && !response.error) {
userLanguage = response.locale;
}
}
);
FB.api(
'me/{namespace}:{action}', 'post',
{
object: {
"url": imageUrl,
"title": appTitle,
"description": appDescription,
"image": imageUrl
}
},
function(response) {
}
);
} else if (response.status === 'not_authorized') {
FB.login( function( response ) {
}, {scope: "publish_actions"} );
} else {
FB.login( function( response ) {
}, {scope: "public_profile"} );
}
我尝试使用此代码,但是 /me
节点 returns 用户数据,我想获取应用程序数据:
FB.api(
"/me",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
您可以通过
获取用户的区域设置
/me?fields=id,locale
然后您可以在应用程序的第二次调用中使用此 locale
:
/{app_id}?fields=id,name,description&locale={locale}
应该可以。您需要知道应用程序 ID 并将 {app_id}
替换为它。 locale
参数定义了您希望在其中接收数据的语言环境。
请注意,它不一定适用于所有可用的语言环境...
可以在 https://www.facebook.com/translations/FacebookLocales.xml
找到语言环境列表
见
我想知道当用户有权访问我的应用程序数据(标题和描述)并使用用户区域设置获取本地化值时我如何访问它。
我的代码是这样的:
var imageUrl = "http://mysite.test/webroot/img/test_image.jpg",
userID = response.authResponse.userID,
userLanguage,
appTitle,
appDescription;
if (response.status === 'connected') {
FB.api(
"/" + userID,
function (response) {
if (response && !response.error) {
userLanguage = response.locale;
}
}
);
FB.api(
'me/{namespace}:{action}', 'post',
{
object: {
"url": imageUrl,
"title": appTitle,
"description": appDescription,
"image": imageUrl
}
},
function(response) {
}
);
} else if (response.status === 'not_authorized') {
FB.login( function( response ) {
}, {scope: "publish_actions"} );
} else {
FB.login( function( response ) {
}, {scope: "public_profile"} );
}
我尝试使用此代码,但是 /me
节点 returns 用户数据,我想获取应用程序数据:
FB.api(
"/me",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
您可以通过
获取用户的区域设置/me?fields=id,locale
然后您可以在应用程序的第二次调用中使用此 locale
:
/{app_id}?fields=id,name,description&locale={locale}
应该可以。您需要知道应用程序 ID 并将 {app_id}
替换为它。 locale
参数定义了您希望在其中接收数据的语言环境。
请注意,它不一定适用于所有可用的语言环境...
可以在 https://www.facebook.com/translations/FacebookLocales.xml
找到语言环境列表见