Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:使用GraphRequest NewmereRequest获取并存储Facebook名称_Android_Facebook_Facebook Graph Api_Android Studio - Fatal编程技术网

Android:使用GraphRequest NewmereRequest获取并存储Facebook名称

Android:使用GraphRequest NewmereRequest获取并存储Facebook名称,android,facebook,facebook-graph-api,android-studio,Android,Facebook,Facebook Graph Api,Android Studio,我想在我的应用程序中获取通过facebook连接的人的姓名。我在《成功论》中使用了这种方法: private LoginButton loginbutton2; private ProfilePictureView fAvatar2; private TextView fName2; private FacebookCallback<LoginResult> mCallback2 = new FacebookCallback<LoginResult&g

我想在我的应用程序中获取通过facebook连接的人的姓名。我在《成功论》中使用了这种方法:

    private LoginButton loginbutton2;
    private ProfilePictureView fAvatar2;
    private TextView fName2;

private FacebookCallback<LoginResult> mCallback2 = new FacebookCallback<LoginResult>() {
      public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();
            final Profile profile = Profile.getCurrentProfile();

            GraphRequestAsyncTask request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                    /*fName2.setText(profile.getName());
                    fAvatar2.setProfileId(profile.getId());*/
                }
            }).executeAsync();
            }

}

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        setContentView(R.layout.activity_info_account);

        mCallbackManager2 = CallbackManager.Factory.create();
        loginbutton2 = (LoginButton) findViewById(R.id.login_button2);
        loginbutton2.setBackgroundResource(R.drawable.facebookconnexion);
        loginbutton2.setReadPermissions("user_friends");
        loginbutton2.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        loginbutton2.registerCallback(mCallbackManager2, mCallback2);


        fName2 = (TextView) findViewById(R.id.facebookName2);
        fAvatar2 = (ProfilePictureView) findViewById(R.id.facebook_avatar2);
}
私人登录按钮登录按钮2;
私人档案PictureView fAvatar2;
私有文本视图fName2;
private FacebookCallback mCallback2=新建FacebookCallback(){
成功时公共无效(LoginResult LoginResult){
AccessToken AccessToken=loginResult.getAccessToken();
最终配置文件=Profile.getCurrentProfile();
GraphRequestStatSyncTask请求=GraphRequest.NewMereRequest(accessToken,new GraphRequest.GraphJSONObjectCallback()){
@凌驾
未完成公共无效(JSONObject JSONObject,GraphResponse GraphResponse){
/*fName2.setText(profile.getName());
fAvatar2.setProfileId(profile.getId())*/
}
}).executeAsync();
}
}
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
sdkinInitialize(getApplicationContext());
setContentView(R.layout.activity\u info\u账户);
mCallbackManager2=CallbackManager.Factory.create();
loginbutton2=(LoginButton)findViewById(R.id.login_button2);
登录按钮2.setBackgroundResource(R.drawable.facebookconnexion);
loginbutton2.setReadPermissions(“用户朋友”);
loginbutton2.SetCompoundDrawableSwithinInstincBounds(0,0,0,0);
loginbutton2.registerCallback(mCallbackManager2,mCallback2);
fName2=(TextView)findViewById(R.id.facebookName2);
fAvatar2=(ProfilePictureView)findViewById(R.id.facebook\u avatar2);
}
如何将该名称放入我的文本视图(在注释中)?当我不注释这行时:
/*fName2.setText(profile.getName())我有一个错误。
事实上,我如何使用newMeRequest存储名称,以便在之后将其放入文本视图?


Thx,

要获取名称,请执行以下操作

在这个地方

 GraphRequestAsyncTask request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                try {
 fName2.setText(jsonObject.getString("first_name"));
                fAvatar2.setProfileId(jsonObject.getString("profile_id"));<--I am not sure profile_id is the name there do this to see the JSON response
 Log.e("FBGraphResponse", jsonObject.toString());
 } catch(Exception e){e.printStackTrace();}
            }
        }).executeAsync();
GraphRequestStatSyncTask请求=GraphRequest.NewMereRequest(accessToken,new GraphRequest.GraphJSONObjectCallback(){
@凌驾
未完成公共无效(JSONObject JSONObject,GraphResponse GraphResponse){
试一试{
fName2.setText(jsonObject.getString(“名字”);

fAvatar2.setProfileId(jsonObject.getString(“profile_id”);谢谢,这正是我想要的,但是我在jsonObject.getString(“first_name”)上有一个错误:未处理的异常:org.json.JSONException