gpt4 book ai didi

android - Plus.PeopleApi.getCurrentPerson() 返回 null,不再返回

转载 作者:太空狗 更新时间:2023-10-29 16:34:26 27 4
gpt4 key购买 nike

我搜索了很多,但仍然没有找到解决方案。Plus.PeopleApi.getCurrentPerson() 总是返回 null。我得到了调试 SHA1 并发布了 SHA1。它们都作为具有正确包名称的 OAuth 2.0 客户端 ID 添加到控制台。 (遗憾的是,我不能发布图片)这是我的 GoogleApiClient:

    private GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope(Scopes.PROFILE))
.addScope(new Scope(Scopes.PLUS_LOGIN))
.build();
}

很简单。我从 Fragment 的 onCreateView() 调用它。然后我试图让当前的人:

@Override
public void onConnected(Bundle bundle) {
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);

if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
String personName = currentPerson.getDisplayName();
String personGooglePlusProfile = currentPerson.getUrl();
}

而且总是空的。 mGoogleApiClient 工作正常,它连接,它不为空,但仍然如此。在 console->Apis Google+ API 中启用,但在“使用”选项卡中没有任何请求。

我已经尝试了我能找到的所有解决方案,但没有任何帮助。我正在使用 geny 模拟器运行该应用程序。请帮助我,给我任何想法。

添加:这是我几乎完整的 Fragment 类:

    public class AuthorizationFragment2 extends Fragment implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener,
ResultCallback {
private static final String KEY_IS_RESOLVING = "is_resolving";
private static final String KEY_SHOULD_RESOLVE = "should_resolve";
/* Request code used to invoke sign in user interactions. */
protected static final int RC_SIGN_IN = 0;
/* GP Is there a ConnectionResult resolution in progress? */
private boolean mIsResolving = false;
/* GP Should we automatically resolve ConnectionResults when possible? */
private boolean mShouldResolve = false;
private GoogleApiClient mGoogleApiClient;
/* View to display current status (signed-in, signed-out, disconnected, etc) */
private TextView mStatus;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
if (savedInstanceState != null) {
mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING);
mShouldResolve = savedInstanceState.getBoolean(KEY_SHOULD_RESOLVE);
}
mGoogleApiClient = buildGoogleApiClient();
View view = inflater.inflate(R.layout.authorization_view, container, false);
// Register onClickListener for gp_login_button
view.findViewById(R.id.gp_login_button).setOnClickListener(this);
view.findViewById(R.id.sign_out_button).setOnClickListener(this);
mStatus = (TextView) view.findViewById(R.id.mStatus);
return view;
}
@Override
public void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_IS_RESOLVING, mIsResolving);
outState.putBoolean(KEY_SHOULD_RESOLVE, mShouldResolve);
}
@Override
public void onConnected(Bundle bundle) {
Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(this);
// It is allways null
if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
// Retrieve Person's information
}
updateUI(true);
}
@Override
public void onConnectionSuspended(int i) {
Log.d(MainActivity.LOG_TAG, "onCOnnectionSuspended()");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if(!mIsResolving && mShouldResolve) {
if (connectionResult.hasResolution()) {
try {
// It calls the Activity's onActivityResult()
connectionResult.startResolutionForResult(getActivity(), RC_SIGN_IN);
mIsResolving = true;
} catch (IntentSender.SendIntentException e) {
mIsResolving = false;
mGoogleApiClient.connect();
}
} else {
// Could not resolve the connection result, show the user an
// error dialog.
showErrorDialog(connectionResult);
}
} else {
// Show the signed-out UI
updateUI(false);
}
}
private GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(getActivity().getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
/**
* This called only from Activity's onActivityResult() with requestCode == RC_SIGN_IN
*/
protected void connect(int resultCode) {
// If the error resolution was not successful we should not resolve further.
if (resultCode != Activity.RESULT_OK) {
mShouldResolve = false;
}
mIsResolving = false;
mGoogleApiClient.connect();
}
}

和 list :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="somepackage" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>

对于一些编辑错误,我们深表歉意。

最佳答案

我找到了解决方案。它与 fragment 和 SHA1 key 无关。这是关于包名。当我创建项目时,IDE 将包目录设为“somepackage.app”,这不是我需要的,我将其更改为“somepackage”。一切正常,除了 google api。 Gradle 在其配置文件中保存了“applicationId somepackage.app”,我相信它会覆盖 list 的包名称。没有错误,没有连接,什么都没有。我花了大约 15 个小时,我相信我很愚蠢。

关于android - Plus.PeopleApi.getCurrentPerson() 返回 null,不再返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32357293/

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