设置Facebook图形请求以始终返回英文结果 [英] Set Facebook graph Request to always return English results

查看:57
本文介绍了设置Facebook图形请求以始终返回英文结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

返回结果的语言取决于用户电话上的设置和/或他们的位置.我想强制要求仅返回英文结果.所讨论的请求对于用户而言只是一个简单的我"请求.到目前为止,我已经尝试在这样的参数中添加"local":

The language of the results returned depends on the settings on a users phone and/or their location. I want to force the request to only return English results. The request in question is just a simple "me" request for a user. So far I have tried to add "local" in the parameteres like this:

GraphRequest graphRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
        }
    });
    Bundle param = new Bundle();
    param.putString("fields", "albums, id, birthday, photos&locale=en_us");    
    graphRequest.setParameters(param);
    graphRequest.executeAsync();

我也试图这样做:

String graphPath = "/me?fields=id,name , first_name,albums, last_name&locale=en_us";
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), graphPath, null, HttpMethod.GET, new GraphRequest.Callback() {
        @Override
        public void onCompleted(GraphResponse response) {
            Log.i(TAG, "response: " + response);
            Log.i(TAG, "object: " + response.getJSONObject());
        }
    });
    GraphResponse response = request.executeAsync();

两者都没有运气.最后一种方法实际上在Facebook Graph Api Explorer中有效:

Both without any luck. Last method actually works in the Facebooks Graph Api Explorer: https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Dalbums%26locale%3Dnb_no&version=v2.5

在不添加& locale = zh_CN"的情况下,顶部图形请求将按预期工作.

Without adding the "&locale=en_us" the top graph request works as intended.

推荐答案

这实际上是我所拥有的Facebook sdk版本中的一个错误,因此它不会仅返回英文结果.它可以将区域设置"设置为额外的参数.正确的方法是:

It was actually a bug in the Facebook sdk version I had, so it would not return only english results. It works to set "locale" as an extra parameter. The correct way to do it is:

GraphRequest graphRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
        }
    });
    Bundle param = new Bundle();
    param.putString("fields", "gender, email, name, albums");
    param.putString("locale", "en_US");
    graphRequest.setParameters(param);
    graphRequest.executeAsync();

如果这不适用于您,请尝试升级您的Facebook sdk.我现在使用的版本为"com.facebook.android:facebook-android-sdk:4.11.0",它可以完美运行.

If this does not work for you, try to upgrade your Facebook sdk. I'm now on version 'com.facebook.android:facebook-android-sdk:4.11.0' and this works perfectly.

这篇关于设置Facebook图形请求以始终返回英文结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆