gpt4 book ai didi

android - GoogleAccountCredential-[错误]名称不能为空: null - despite permissions

转载 作者:行者123 更新时间:2023-12-03 09:07:34 35 4
gpt4 key购买 nike

我一直在开发一个在某些时候将少量数据发送回Google表格的应用程序,但是我无法使其正常工作:

public void SheetUpdate() {
GoogleAccountCredential mCredential;

Sheets mService;
final String[] SCOPES = { SheetsScopes.SPREADSHEETS };

mCredential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName("oscarcookeabbott@gmail.com");

Log.e("DEBUG", "SheetUpdate: " + mCredential.getSelectedAccountName());

HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

mService = new Sheets.Builder(transport, jsonFactory, mCredential)
.setApplicationName("Listeau")
.build();

/*
String range = "[Sheet Name]![Start]:[End]";

mService.spreadsheets().values().update(enumId, range, valueRange)
.setValueInputOption("RAW")
.execute();
*/

ValueRange values = new ValueRange();
values.set("EMAIL", "tonyjones@abc.net.au");
values.set("AUTH", "[INSERT DATE]");
values.set("SUB", "[INSERT DATE + MONTH]");

try {
mService.spreadsheets().values().append("1meAAvjdPmghn6wl_IKc-_NJx_M85I_yqsn4Nwm_j_X0", "Users", values)
.setValueInputOption("RAW")
.execute();
} catch(IOException e) {
Log.e("BUG", "SheetUpdate: IOException");
}
}

在我的 list 中,我有:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

我收到的错误表明 mCredential的名称未设置( null),该错误在调用mService.execute时被捕获。
我已经手动设置(只是试图查明问题),并在Settings-Apps菜单中以及在Jellybean上尝试了许可,但是所有人都声称存在相同的问题。

[编辑]这是完整的错误输出:
`
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pybuspr.listeriafoodusa/com.pybuspr.listeau.Master}: java.lang.IllegalArgumentException: the name must not be empty: null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: the name must not be empty: null
at android.accounts.Account.<init>(Account.java:48)
at com.google.android.gms.auth.zze.getToken(Unknown Source)
at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:269)
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.pybuspr.listeau.Master.SheetUpdate(Master.java:167)
at com.pybuspr.listeau.Master.onCreate(Master.java:48)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method)

`

最佳答案

您的execute()调用通过您创建的GoogleAccountCredential对象进行,并且在内部失败。

查看开放源代码Account.java的代码,您可以看到传入的名称为null。调用者GoogleAuthUtil是Play服务库的封闭源代码部分,但是我们可以很好地猜测发生了什么。它尝试从手机的设置中获取Google帐户,但找不到匹配项。

您已经怀疑,权限是此处的一个因素,我认为这是导致失败的原因。以Android 6及更高版本为目标时,在 list 中声明权限可能不够,在您的情况下,GET_ACCOUNTS受此影响。参见here

您需要在运行时请求权限(并彻底处理用户拒绝权限的情况)。请参阅here以了解有关操作方法。或者,如果您没有任何相关的依存关系,则可以将目标级别降低到5.1或更低,并且至少现在,它将使用较旧的权限模型。

关于android - GoogleAccountCredential-[错误]名称不能为空: null - despite permissions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41219555/

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