本文将介绍drive.changes的详细情况,特别是关于。watch返回GoogleJsonResponseException:401未经授权,未显示任何消息的相关信息。我们将通过案例分析、数据研究
本文将介绍drive.changes的详细情况,特别是关于。watch返回GoogleJsonResponseException:401未经授权,未显示任何消息的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于500内部服务器错误v3上传API:GoogleJsonResponseException、Android json错误com.google.gson.JsonSyntaxException:java.lang.IllegalStateException、android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端、android – 使用JSON API将文件上传到Google云端存储,错误401未经授权的知识。
本文目录一览:- drive.changes()。watch返回GoogleJsonResponseException:401未经授权,未显示任何消息
- 500内部服务器错误v3上传API:GoogleJsonResponseException
- Android json错误com.google.gson.JsonSyntaxException:java.lang.IllegalStateException
- android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端
- android – 使用JSON API将文件上传到Google云端存储,错误401未经授权
drive.changes()。watch返回GoogleJsonResponseException:401未经授权,未显示任何消息
我正在尝试监视Google云端硬盘中的更改,并收到401异常。在这里搜索时,我发现人们有详细的消息,尽管我一无所有,但为什么他们未被未经授权。
这是我使用的代码:
public static void main(String[] args) { try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // authorization GoogleCredential credential = GoogleCredential.getApplicationDefault() .createScoped(DriveScopes.all()); boolean refreshed = credential.refreshToken(); // set up the global Drive instance drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME) .build(); Channel channel = new Channel(); channel.setId(UUID.randomUUID().toString()); channel.setType("web_hook"); //my ip here channel.setAddress("https://com.example:"); StartPageToken pageToken = drive.changes().getStartPageToken().execute(); System.out.println(pageToken.getStartPageToken()); Channel changesChannel = drive.changes().watch(pageToken.getStartPageToken(), channel).execute(); System.out.println(changesChannel.getExpiration()); return; } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } System.exit(1);}
更多信息:
- 这是一个服务帐户。它具有所有者权限
- 我正在从本地计算机使用它
- drive.files()。list()工作正常
- drive.about()。get()正常工作
而且我得到的例外是:
com.google.api.client.googleapis.json.GoogleJsonResponseException:401在com.google.api.client.googleapis上的com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)未经授权。
com.google.api.client.googleapis上com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)上的services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)。
services.AbstractGoogleClientRequest $
1.interceptResponse(AbstractGoogleClientRequest.java:321)在com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)在com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed
(AbstractGoogleClientRequest.java:419),位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)的com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
.lambda.GoogleDrive2.main(MyClass.java:142)
我的pom.xml依赖项:
<dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client</artifactId> <version>1.20.0</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client</artifactId> <version>1.22.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client-extensions --> <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client-extensions</artifactId> <version>1.6.0-beta</version> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> <version>1.22.0</version> </dependency> <dependency> <groupId>com.google.apis</groupId> <artifactId>google-api-services-drive</artifactId> <version>v3-rev70-1.22.0</version> </dependency>
答案1
小编典典花了几个小时并仔细阅读了文档后,我终于找到了问题。
按照推送通知文档(https://developers.google.com/drive/v3/web/push)的规定:
要使用推送通知,您需要做三件事:
注册您的接收URL的域。…
设置您的接收URL或“ Webhook”回调接收器。
这是HTTPS服务器,用于处理资源更改时触发的API通知消息。
- 为您要观看的每个资源端点设置一个通知通道。
通道指定通知消息的路由信息。作为频道设置的一部分,您可以标识要在其中接收通知的特定URL。每当频道的资源发生变化时,Drive
API都会向该URL发送一条通知消息,作为POST请求。
这意味着您应该拥有一个域,并且应该先在Google上进行确认,然后才能使用watch API。
附GoogleJsonResponseException: 401Unauthorized
言:在这种情况下,我仍然认为回应是荒谬的,但希望它能帮助其他面临相同问题的人。
500内部服务器错误v3上传API:GoogleJsonResponseException
当使用Java的Youtube API示例将文件上传到youtube时,我得到以下信息:
在此行出现错误: 视频返回视频= videoInsert.execute();
错误堆栈
com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error{ "code" : 500, "message" : null} at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113) at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460) at com.omp.util.YoutubeUtil.uploadVideo(YoutubeUtil.java:141)
这里已经引发了一个相关的问题: https : //code.google.com/p/gdata-
issues/issues/detail?id=6352
答案1
小编典典一两天后自动解决!绝对是API问题。
Android json错误com.google.gson.JsonSyntaxException:java.lang.IllegalStateException
我在解析json数据时遇到此错误
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2
我无法找到解决方案.我的json数据是:
{
"user": [
{
"email": "wijden@jerseyrest.com",
"firstName": "Wijden",
"id": "1",
"lastName": "User"
}, {
"email": "user@jerseyrest.com",
"firstName": "Sample",
"id": "2",
"lastName": "User"
}, {
"email": "ingenieur@jerseyrest.com",
"firstName": "Ingenieur",
"id": "3",
"lastName": "User"
}
]
}
这就是我做到的方式:
Type type = new Typetoken<List<WorkItem>>() { }.getType();
List<WorkItem> workitems = (List<WorkItem>) new Gson().fromJson(resultat, type);
如果你能帮助我解决问题,我将不胜感激.提前致谢
解决方法:
为了解析你的JSON,我创建了包装响应的类,即:
public class Response {
@Serializedname("user")
private List<User> userList;
//getters and setters
}
和,
public class User{
@Serializedname("id")
private int id;
@Serializedname("email")
private String email;
@Serializedname("firstName")
private String firstName;
@Serializedname("lastName")
private String lastName;
//getters and setters
}
然后,为了解析您的JSON响应,您只需要:
Gson gson = new Gson();
Response data = gson.fromJson(yourjsonString, Response.class);
然后,您可以非常轻松地访问您的数据,例如:
User user = data.getUserList.get(i);
注意:使用注释@Serializedname对于分离JSON响应中和应用程序中的字段名称很有意义,以便遵循Java命名约定…
android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端
https://developers.google.com/eclipse/docs/running_and_debugging_2_0
它基本上为我现有的应用程序添加了GAE后端.然后,我尝试下面的示例,在本地开发服务器上运行它,然后我得到下面发生的异常
Note result = endpoint.insertNote(note).execute();
叫做.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
我的代码如下.
package com.cloudnotes; import java.io.IOException; import java.util.Date; import android.os.AsyncTask; import android.content.Context; import com.cloudnotes.noteendpoint.Noteendpoint; import com.cloudnotes.noteendpoint.model.Note; import com.google.api.client.extensions.android.http.AndroidHttp; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestinitializer; import com.google.api.client.json.jackson.JacksonFactory; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new EndpointsTask().execute(getApplicationContext()); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main,menu); return true; } public class EndpointsTask extends AsyncTask<Context,Integer,Long> { protected Long doInBackground(Context... contexts) { Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder( AndroidHttp.newCompatibleTransport(),new JacksonFactory(),new HttpRequestinitializer() { public void initialize(HttpRequest httpRequest) { } }); Noteendpoint endpoint = CloudEndpointUtils.updateBuilder( endpointBuilder).build(); try { Note note = new Note().setDescription("Note Description"); String noteID = new Date().toString(); note.setId(noteID); note.setEmailAddress("E-Mail Address"); Note result = endpoint.insertNote(note).execute(); } catch (IOException e) { e.printstacktrace(); } return (long) 0; } } }
解决方法
<?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>APPLICATION_ID_HERE</application>
…
</appengine-web-app>
android – 使用JSON API将文件上传到Google云端存储,错误401未经授权
我相信的问题是获得正确的API密钥身份验证.上传的图片是公开的图片,但仅向我的应用用户公开,因此阅读Authorize Requests文档说我不需要为公共数据提供OAuth密钥,我只需发送一个API密钥
Public API access: A request that does not provide an OAuth 2.0 token
must send an API key. The key identifies your project and provides API
access,quota,and reports.
所以我去我的控制台从我的调试和生产密钥库的SHA1创建了一个密钥(API Manager / Credentials / Create Credentials / API Key).
这些API密钥是正确的,因为它们与谷歌登录等其他谷歌服务一起使用,它们工作正常.
当我尝试提出启动可恢复上传的请求时,这就是我所做的
String sUrl = "https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable&name="+mImgName; URL url = new URL(sUrl); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestProperty("Authorization","AIzaSyDT...."); urlConnection.setRequestProperty("X-Upload-Content-Type","image/png"); urlConnection.setRequestProperty("X-Upload-Content-Length",String.valueOf(fileSize)); urlConnection.setRequestMethod("POST");
但我得到错误401未经授权,所以我假设它是我发送的密钥的问题.
我还在Authorize Requests文档的末尾看到它声明我可以将我的密钥作为请求URL的参数
After you have an API key,your application can append the query
parameter key=yourAPIKey to all request URLs.
所以我不知道我是否想要这样做或者在请求中设置了Authorization属性,还是两者都设置了?
关键是我创建了错误类型的密钥,或者我在这里缺少什么?
解决方法
但是除非您的存储桶启用了公共写入(通常您不想这样做),否则您仍需要使用身份验证来上传到存储桶.
在你的情况下,我想你可能想要使用Signed URLs.
今天关于drive.changes和。watch返回GoogleJsonResponseException:401未经授权,未显示任何消息的介绍到此结束,谢谢您的阅读,有关500内部服务器错误v3上传API:GoogleJsonResponseException、Android json错误com.google.gson.JsonSyntaxException:java.lang.IllegalStateException、android – GoogleJsonResponseException:404 Not Found使用谷歌应用程序端点引擎后端、android – 使用JSON API将文件上传到Google云端存储,错误401未经授权等更多相关知识的信息可以在本站进行查询。
本文标签: