Tag: google oauth

使用Java blogger API v3动态发布在博客上

关于使用Java blogger API v3动态地将post发布到我的博客帐户,我有两个问题。 第一 我使用以下代码获取访问我的博客的凭据: GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(emailAddress) .setServiceAccountPrivateKeyFromP12File( new File(p12FileLocation)) .setServiceAccountScopes(Collections.singleton(BloggerScopes.BLOGGER)) .build(); credential.setAccessToken(“zRLqmkM82626Uym9Uv1Jsdd”); Blogger blogger = new Blogger.Builder(httpTransport, JSON_FACTORY, credential) .setApplicationName(“Blogger”) .build(); // …. rest of the code to prepare post and send it …… 我设置了以下google页面生成的访问令牌(credential.setAccessToken): https : //developers.google.com/oauthplayground 但是此令牌每3600秒过期一次。 所以我再次访问该页面并按下“刷新访问令牌”按钮以获取另一个并在上面的代码中再次使用它。 这是访问我的博客和以编程方式动态发布内容和文章的正确方法吗? 第二 在谷歌开发者控制台https://developers.google.com/console我看到我有10000个请求/天和1个请求/秒/用户的限制 但 在使用我的上述代码动态正确发布大约50个post之后(注意我在连续请求之间设置等待大约5秒),我开始从api调用中收到以下错误: { “code” […]

使用OAuth2以编程方式向Google进行身份validation

如何以编程方式向Google进行身份validation? 现在不推荐使用ClientLogin( https://developers.google.com/accounts/docs/AuthForInstalledApps ),我们如何使用OAuth2对Google执行程序化身份validation? 使用ClientLogin,我们可以使用电子邮件和密码参数向https://www.google.com/accounts/ClientLogin发送post并获取身份validation令牌。 使用OAuth2我找不到解决方案! # 我的应用程序是一个java后台进程。 我看到,点击此链接:developers.google.com/accounts/docs/OAuth2InstalledApp#refresh,如何使用刷新的令牌获取新的访问令牌。 问题是,当我有一个新的有效访问令牌时,我找不到一个关于如何实例化Analytics对象(例如)来执行查询的java示例 这是我的代码,在调用“execute()”时返回401无效凭据: public class Test { static final String client_id = “MY_CLIENT_ID”; static final String client_secret = “MY_SECRET”; static final String appName = “MY_APP”; private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); private static final JsonFactory JSON_FACTORY = new JacksonFactory(); static String access_token = “xxxx”; static […]

使用Google表格API和服务帐户时禁止使用403

我有一个使用服务帐户的应用程序(因为它从一个cron作业运行,因此我无法通过浏览器中的用户进行授权)。 以下是我创建工作表服务的方法: private static final String APPLICATION_NAME = “my app”; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static HttpTransport HTTP_TRANSPORT; static { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException | IOException e) { e.printStackTrace(); } } private static final List SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS); private static Credential authorize() throws IOException, GeneralSecurityException { GoogleCredential credential […]

无法使用java API(oAuth2)将video上传到youtube。 接收403禁止访问。 请求可能未得到适当授权

我有一个将video上传到YouTube的应用程序。 自24 bb以来,我的应用程序存在严重的上传function问题。 我正在使用youtube的官方谷歌java客户端(以及oauth)。 我收到的问题403 Forbidden使用video上传API。 刷新令牌,auth bearer标头都可以。 当我第一次运行我的应用程序时,它成功上传了1-2个video,然后稍后它从谷歌接收403新请求,重新使用相同的连接授权。 我甚至在oauth游乐场重现了这个问题。 如何重现? 在google oauth playground中输入应用程序oauth凭据 授权youtube.upload API 交换身份validation令牌以获取刷新令牌 从api测试部分执行POST到https://www.googleapis.com/upload/youtube/v3/videos?part=id&prettyPrint=true&uploadType=resumable – 它应该在上传之前创建空的video存根 前1-3次POST会创建具有正确youtubevideoID的video存根,但稍后它会响应: { “error”: { “code”: 403, “message”: “Access forbidden. The request may not be properly authorized.”, “errors”: [ { “domain”: “youtube.common”, “message”: “Access forbidden. The request may not be properly authorized.”, “reason”: “forbidden” } ] […]

google oauth2使用user@gmail.com模拟服务帐户

我想访问一些谷歌API服务: GDrive API 联系API People API 我正在努力使用oauth2模拟服务帐户流程(您知道其中一个: Google Oauth v2 – 服务帐户说明 。要进行模拟,您需要在Google Apps控制台中应用“委派域范围权限”,下载对应的pk12文件并激活谷歌控制台项目中的API。 目前我总是得到: com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at oauthsample.GDriveAPI.(GDriveAPI.java:50) at oauthsample.GDriveAPI.main(GDriveAPI.java:85) 这是我的代码: HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); Set scopes = new HashSet(); scopes.add(“https://www.google.com/m8/feeds”); GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) […]

无法使用Google API 获取服务帐户流的令牌

我正在使用Google API(版本为google-oauth-java-client-1.12.0-beta)获取OAuth2访问令牌但返回“invalid_grant”。 参考: https : //developers.google.com/accounts/docs/OAuth2ServiceAccount 这是代码: import com.google.api.client.auth.jsontoken.JsonWebSignature; import com.google.api.client.auth.jsontoken.JsonWebToken; import com.google.api.client.auth.jsontoken.RsaSHA256Signer; import com.google.api.client.auth.oauth2.TokenRequest; import com.google.api.client.auth.oauth2.TokenResponse; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.util.Clock; import java.io.FileInputStream; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; public class TestClient { private static PrivateKey getPrivateKey(String […]