我们或许天真地决定,我们应该将我们的许多库从两年前的1.12.0-betas更新到漂亮的新版本1.20.0.例如:我们将google-http-client-1.12.0-beta.jar更新为google-http-client-android-1.20.0.jar.
当我们执行此代码时:
List<String> scopes = Lists.newArrayList(SendToGoogleUtils.FUSION_TABLES_SCOPE);
GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(
context, account.name, scopes );
if (credential == null) {
return false;
}
Fusiontables fusiontables = new Fusiontables.Builder(
AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
Run Code Online (Sandbox Code Playgroud)
我们得到这个惊人的错误报告:
FATAL EXCEPTION Caused by: java.lang.NoSuchMethodError: No direct method <init>(Lcom/google/api/client/http/HttpTransport;Lcom/google/api/client/http/HttpRequestInitializer;Ljava/lang/String;Ljava/lang/String;Lcom/google/api/client/json/JsonObjectParser;Lcom/google/api/client/googleapis/services/GoogleClientRequestInitializer;Ljava/lang/String;Z)V in class Lcom/google/api/client/googleapis/services/json/AbstractGoogleJsonClient; or its super classes (declaration of 'com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient' appears in /data/app/dkr.ajijic.apps.tm-1/base.apk)
Run Code Online (Sandbox Code Playgroud)
有人知道怎么解读吗?我们当然不会!
有关如何以编程方式获取oauth2授权的示例代码.我复制了代码并命名了我的类UtubeUploadAll.我的代码如下:
private Credential authorize(List<String> scopes) throws Exception {
// Load client secrets.
InputStream cs = UtubeUpload.class.getResourceAsStream(
"/client_secret.json");
GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
Run Code Online (Sandbox Code Playgroud)
该声明:
InputStream cs = UtubeUpload.class.getResourceAsStream(
"/client_secret.json");
Run Code Online (Sandbox Code Playgroud)
总是返回null,无论我把client_secrets.json文件放在哪里.我把它放在目录src,src/main,src/main/java,src/main/res ......我能想到的每个地方.我必须在这里完全误解,但我不知道是什么.有人可以帮帮我吗?
Google的Oauth2库方法需要一个针对scopes参数的Java列表.将参数编码为List
文字是否合理,如下所示:
public static final List<String> YOUTUBE_SCOPES = Lists.newArrayList(
"https://www.googleapis.com/auth/youtube.upload",
"https://www.googleapis.com/auth/youtube.readonly");
Run Code Online (Sandbox Code Playgroud)
这样我就可以:
SendToGoogleUtils.getGoogleAccountCredential(activity, accountName, YOUTUBE_SCOPES );
Run Code Online (Sandbox Code Playgroud)
Java编译器是否会创建有效的YOUTUBE_SCOPES文字?