我正在使用服务帐户通过管理目录和Google+域API成功模拟管理员用户,但我无法弄清楚网站是否可以使用服务帐户。它甚至有可能吗?我指的是允许您创建和删除网站的API,而不是用于管理内容的网站管理员工具API等。可能在Sites API中使用Google服务帐户
0
A
回答
0
是的,它是可能的。下面是一个代码示例:
SitesService sitesService = new SitesService("MyApplication");
final GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory())
.setServiceAccountId("XXXX.apps.googleusercontent.com")
.setServiceAccountScopes(Collections.singleton(SERVICE_SCOPES))
.setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
.setServiceAccountUser("[email protected]").build();
sitesService.setOAuth2Credentials(credential);
你必须与谨慎的唯一的事情,就是一些SitesService
方法可能无法正确地刷新令牌,在这种情况下,你将不得不赶上SessionExpiredException
并刷新Credential
你自己。
0
Google Sites API网页上说[1]您可以使用它创建新网站或复制现有网站。
1
您可以使用网站的API服务帐户。您只需使用SignedJwtAssertionCredentials,从后台模拟用户并访问GData API。
这里是代码片段:
credentials = SignedJwtAssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
file(SERVICE_ACCOUNT_PEM_FILE_PATH, "rb").read(),
scope=["https://sites.google.com/feeds/"],
prn=userEmailYouWantToImpersonate
)
http = httplib2.Http()
http = credentials.authorize(http)
sitesClient = gdata.sites.client.SitesClient(source='mycompany', site='mySite', domain='mydomain')
sitesClient.auth_token = TokenFromOAuth2Creds(credentials)
feed = sitesClient.GetContentFeed()
class TokenFromOAuth2Creds:
def __init__(self, creds):
self.creds = creds
def modify_request(self, req):
if self.creds.access_token_expired or not self.creds.access_token:
self.creds.refresh(httplib2.Http())
self.creds.apply(req.headers)
相关问题
- 1. 以“服务帐户”身份连接到Google Sites API
- 2. 在Google Analytics(分析)中使用服务帐户.Net API v3.0
- 3. 使用服务帐户在PHP上使用Google Calendar API
- 4. Google API服务帐户和nodejs
- 5. Google OAuth2服务帐户API授权
- 6. 带有服务帐户的Google Reports API
- 7. Google API CPP客户端 - 使用服务帐户
- 8. Google活动api服务帐户403
- 9. Google驱动器API和服务帐户
- 10. 我可以在Google Analytics中使用服务帐户吗?
- 11. google api服务帐户访问用户任务列表
- 12. 使用服务帐户访问Google Analytics API
- 13. ColdFusion - >使用oauth 2和服务帐户的Google Analytics API
- 14. 使用应用服务帐户的iOS版Google Drive API
- 15. 使用服务帐户访问Google Analytics API不起作用
- 16. 使用Google Drive V3 API和服务帐户验证,WebViewLink为空
- 17. 使用服务帐户致电Google Glass Mirror API
- 18. 使用服务帐户凭证访问Google课堂API
- 19. Google Calendar API FreeBusy使用服务帐户访问
- 20. 使用Google API服务帐户共享打印机
- 21. invalid_grant使用服务帐户和Google Drive API返回
- 22. 服务帐户认证如何与Ruby Google API一起使用?
- 23. 使用服务帐户连接到Google API Consol中的预测API
- 24. 可以通过服务帐户授权访问哪些Google API?
- 25. 使用服务帐户的Google API访问oauth2client.client.CryptoUnavailableError:没有可用的加密库
- 26. 使用Google Admin SDK使用服务帐户创建用户?
- 27. Google Sites API + OAuth2(在Appengine上)
- 28. 谷歌API服务帐户
- 29. Google API的用户费率限制和服务帐户
- 30. Google日历列表对于使用API的服务帐户不可见
是的,我已经使用该API创建站点(使用Java版本),但我使用用户/传球组合登录,并且我想使用服务帐户模仿用户,因为我正在使用Directory ,Google +或Google日历API。 – momo