我的應用程序允許用戶與Facebook連接。我想在登錄Facebook之後獲得userprofile
信息(使用Facebook SDK 4.0.1)。我認爲我應該使用aynctask
來得到它,但我不知道如何。在下次活動中使用facebook sdk 4.0.1登錄後獲取用戶配置文件android
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
{
@Override
public void onSuccess(LoginResult loginResult)
{
System.out.println("onSuccess");
msginfo.setText("You can now share image on facebook");
otherview.setVisibility(View.VISIBLE);
GraphRequest request = GraphRequest.newMeRequest
(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback()
{
@Override
public void onCompleted(JSONObject object, GraphResponse response)
{
// Application code
Log.v("LoginActivity", response.toString());
//System.out.println("Check: " + response.toString());
try
{
String id = object.getString("id");
idT.setText(object.getString("id"));
ppv.setProfileId(object.getString("id"));
nameT.setText(object.getString("name"));
emailT.setText(object.getString("email"));
locationT.setText(object.getString("address"));
String name = object.getString("name");
String email = object.getString("email");
String gender = object.getString("gender");
String birthday = object.getString("birthday");
// String location = object.getString("location");
// String location = object.getString("user_location");
// String location = object.getString("address");
System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + birthday);
// locationT.setText(location);
}
catch (JSONException e)
{
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday,link");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel()
{
System.out.println("onCancel");
}
@Override
public void onError(FacebookException exception)
{
System.out.println("onError");
Log.v("LoginActivity", exception.getCause().toString());
}
});
,我還可以在當前的活動,但不會在未來一個獲取配置文件信息。
你能解釋一下嗎?你想要什麼? – Soham
爲類中的所有數據創建gatter和setter方法..並設置值並在其他活動中獲取值.. – Destro
@Soham我希望當用戶連接Facebook時,他可以在下一個活動中看到他的信息(用戶名, profileimage)。 –