我正在尝试在我的Android应用程序项目中调用修改Google Keep的方法。现在我只想让构建器能够处理任务。
依赖关系:
implementation("com.google.firebase:firebase-auth:22.3.1")
implementation("com.google.android.gms:play-services-auth:21.1.0")
implementation ("com.google.api-client:google-api-client:2.4.0")
implementation ("com.google.apis:google-api-services-keep:v1-rev20210528-1.31.0")
我要修复的代码:
public class KeepQuickstart {
public static void createNewNote(Context context){
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
if (account != null) {
String idToken = account.getIdToken();
GoogleCredentials credentials = GoogleCredentials.create(new AccessToken(idToken, null));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
try{
Keep keepService = new Keep.Builder(new NetHttpTransport(), GsonFactory.getDefaultInstance(), requestInitializer)
.setApplicationName("Ecco6").build();
// Create note content
Section noteBody = new Section().setText(new TextContent().setText("Finish preparations by tomorrow!"));
Note newNote = new Note().setTitle("Customer call next week").setBody(noteBody);
// Create the note
try {
keepService.notes().create(newNote).execute();
// Handle success, e.g., show a toast message
} catch (Exception e) {
// Handle creation failure
e.printStackTrace();
}
}catch (ExceptionInInitializerError e){
System.out.println(e.getCause().toString());
}
} else {
// User is not signed in, handle this case
System.out.println("User not logged in.");
}
}
}
我真的很难找到在我的 Android 应用程序中使用 API 的方法,但我觉得我已经很接近了。但现在我遇到了一个错误,我不知道如何修复。当我调用 createNewNote 方法时,出现错误:
java.lang.IllegalStateException: You are currently running with version 2.4.0 of google-api-client. You need at least version 1.31.1 of google-api-client to run version 1.31.0 of the Google Keep API library.
非常感谢任何帮助!!
我尝试了不同的方法来传递 HttpRequestInitializer,因此令牌是正确的,并且我可以访问用户的注释,但到目前为止没有任何效果,我对当前的错误消息感到困惑。
使用最新的库版本:
implementation ("com.google.apis:google-api-services-keep:v1-rev20220322-2.0.0")