gpt4 book ai didi

android - 获取 token DrEdit android 示例失败

转载 作者:太空宇宙 更新时间:2023-11-03 10:23:20 26 4
gpt4 key购买 nike

我正在尝试运行 drive sdk android 示例 DrEdit ,但我遇到了一个异常(exception):

04-23 16:49:19.642: E/DriveSyncAdapter(11914): Failed to get token
04-23 16:49:19.642: W/System.err(11914): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
04-23 16:49:19.642: W/System.err(11914): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
04-23 16:49:19.642: W/System.err(11914): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
04-23 16:49:19.642: W/System.err(11914): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)
04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncer.getDriveService(DriveSyncer.java:381)
04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncer.<init>(DriveSyncer.java:94)
04-23 16:49:19.642: W/System.err(11914): at com.example.android.notepad.DriveSyncAdapter.onPerformSync(DriveSyncAdapter.java:32)
04-23 16:49:19.642: W/System.err(11914): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)

开启:

credential.getToken();

在 DriveSyncer.getDriveService() 中。

我已经在 list 中更改了我的 Id,并设置了适当的权限:

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
...
<meta-data
android:name="com.google.android.apps.drive.APP_ID"
android:value="id=XXXXXXXX.apps.googleusercontent.com" />

并且还启用了驱动器 API 并设置了凭据。

在我的 Android 设备中,它会询问我的帐户,但从不询问其他授权,它会显示通知,但仅此而已。但是,快速入门示例运行完美。

我收到错误的代码是:

      private Drive getDriveService() {
if (mService == null) {
try {
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(mContext, DriveScopes.DRIVE_FILE);
credential.setSelectedAccountName(mAccount.name);
// Trying to get a token right away to see if we are authorized
credential.getToken();
Log.e("MyTag", "Never Called");
mService = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
new GsonFactory(), credential).build();
} catch (Exception e) {
Log.e(TAG, "Failed to get token");
// If the Exception is User Recoverable, we display a notification that will trigger the
// intent to fix the issue.
if (e instanceof UserRecoverableAuthException) {
UserRecoverableAuthException exception = (UserRecoverableAuthException) e;
(NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent authorizationIntent = exception.getIntent();
authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
authorizationIntent, 0);
Notification notification = new Notification.Builder(mContext)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setTicker("Permission requested")
.setContentTitle("Permission requested")
.setContentText("for account " + mAccount.name)
.setContentIntent(pendingIntent).setAutoCancel(true).build();
notificationManager.notify(0, notification);
} else {
e.printStackTrace();
}
}
}
return mService;
}

任何想法都会很棒。谢谢。

最佳答案

即使我只运行原始的 DrEdit,我也有同样的问题。权限请求显示在通知栏,但点击后没有反应。

附言。我用HTC 4.0.1 和Google phone 试过这个问题,但都没有用。

不管怎样,这篇文章解决了我的问题,你可以试试这个。 https://stackoverflow.com/a/16535080/1645840

唯一不同的是我调用了这个函数,它仍然有效。

GoogleAuthUtil.getTokenWithNotification(mContext,
mAccount.name, "oauth2:" + DriveScopes.DRIVE_FILE,
null);//, mAuthority, mSyncBundle);

关于android - 获取 token DrEdit android 示例失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16180113/

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