gpt4 book ai didi

java - Android Facebook sdk GraphRequest 在获取用户信息时返回 null

转载 作者:行者123 更新时间:2023-12-02 12:28:06 26 4
gpt4 key购买 nike

我正在尝试使用 Facebook API 允许用户登录我的应用程序,登录操作成功完成,并且我获得了访问 token ,但是当我使用 GraphRequest 获取用户信息时,它的响应和对象返回 null ,我在android开发方面完全是新手。这是我的代码:

    public class SignIn extends Fragment {

private LoginButton loginButton;
private CallbackManager callbackManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragment_sign_in, container, false);
Button button = (Button) v.findViewById(R.id.button_signin);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getActivity(),Home.class);
startActivity(i);
getActivity().finish();
}
});

callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) v.findViewById(R.id.facebook_button);
loginButton.setReadPermissions("email");
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
= try {
Log.d("id",object.getString("id")) ;
Log.d("email",object.getString("email")) ;

} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getActivity().getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();
}

@Override
public void onCancel() {
}

@Override
public void onError(FacebookException exception) {
}
});
return v ;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}

build.gradle(项目)(如果需要)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

我发现我忘了在 list 中添加它:

<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />

关于java - Android Facebook sdk GraphRequest 在获取用户信息时返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45402174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com