コールgetFBUser(accessToken)
FacebookUtils.getInstance(MainActivity.this).getFBUser(accessToekn);
このクラスを追加し、
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.facebook.AccessToken;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.HttpMethod;
import org.json.JSONObject;
public class FacebookUtils {
private static FacebookUtils _FacebookUtils;
private static Context context;
private String TAG = FacebookUtils.class.getSimpleName();
private FacebookUtils(Context context) {
FacebookUtils.context = context;
}
public static FacebookUtils getInstance(Context context) {
if (null == _FacebookUtils) {
synchronized (FacebookUtils.class) {
if (null == _FacebookUtils) {
_FacebookUtils = new FacebookUtils(context);
}
}
}
return _FacebookUtils;
}
public void getFBUser(final AccessToken accessToken) {
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.d(TAG, "FB details are: " +
response.toString());
Log.d(TAG, "FB response.getRawResponse(): " +
response.getRawResponse());
Log.d(TAG, "FB response.getJSONObject(): " +
response.getJSONObject());
Bundle bundle = new Bundle();
bundle.putString("Details", response.getRawResponse());
Message message = new Message();
message.setData(bundle);
// callback.handleMessage(message);
try {
getFbUserDetails(response.getJSONObject().getString("id"), accessToken);
} catch (Exception exception) {
exception.toString();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,email");
request.setParameters(parameters);
request.executeAsync();
}
public void getFbUserDetails(String userId, AccessToken accessToken) {
new GraphRequest(
accessToken,
"/" + userId,
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
Log.d(TAG, "Response of User Details: " + response.toString());
Bundle bundle = new Bundle();
bundle.putString("Details", response.toString());
Message message = new Message();
message.setData(bundle);
// callback.handleMessage(message);
}
}
).executeAsync();
}
}
あなたが質問を手の込んだを試してみてください? – g7pro
** https://developers.facebook.com/docs/facebook-login/android**から参照を取得してください –