【发布时间】:2017-01-15 08:32:00
【问题描述】:
您好,我想获取当前用户在 android 中订阅的频道列表。
我遵循的步骤:
1) https://developers.google.com/youtube/v3/docs/subscriptions/list
通过阅读描述,我在 google 开发者控制台中创建了 API 密钥 和 oauth 密钥并厌倦了实现以下请求
GET https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mine=true&key={YOUR_API_KEY}。你可以看到我只设置了part = snippet 和mine = true。
为了验证我关注了https://developer.android.com/training/id-auth/authenticate.html
这是我的代码
AccountManager am = AccountManager.get(this);
Bundle options = new Bundle();
am.getAuthToken(
myAccount_, // Account retrieved using getAccountsByType()
"Manage your tasks", // Auth scope
options, // Authenticator-specific options
this, // Your activity
new OnTokenAcquired(), // Callback called when a token is successfully acquired
new Handler(new OnError())); // Callback called if an error occurs
添加适当的权限后,我可以在 myAccount_ 中获取我的帐户
关于TokenAcquire
的回调private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
@Override
public void run(AccountManagerFuture<Bundle> result) {
// Get the result of the operation from the AccountManagerFuture.
Bundle bundle = result.getResult();
// The token is a named value in the bundle. The name of the value
// is stored in the constant AccountManager.KEY_AUTHTOKEN.
token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
...
}
}
我没有获得令牌价值。
请指导我。 是否有其他方法或者是否必须更新/修改某些内容?
我在 xml 中的权限是
<uses-permission android:name="android.permission.ACCOUNT_MANAGER" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
在我的异常处理捕获中,token = bundle.getString(AccountManager.KEY_AUTHTOKEN); 这一行出现错误。
android.accounts.AuthenticatorException。 尝试在空对象引用上调用虚拟方法“java.lang.String android.os.Bundle.getString(java.lang.String)”
我使用的是 android 6.0,它需要运行时权限。
【问题讨论】:
-
粘贴完整的错误代码
-
android.accounts.AuthenticatorException
-
尝试在空对象引用上调用虚拟方法'java.lang.String android.os.Bundle.getString(java.lang.String)'......
-
token = bundle.getString(AccountManager.KEY_AUTHTOKEN);这里我出错了
标签: unity3d youtube-api android-youtube-api