gpt4 book ai didi

java - 使用 Oath 对 Google 网站中的 contentfeed 执行查询时 token 无效

转载 作者:行者123 更新时间:2023-12-01 05:27:05 26 4
gpt4 key购买 nike

我正在努力让它发挥作用。当我使用客户端登录方法(用户名/密码)时它工作正常,但使用誓言时它不起作用。我想知道为什么。

我正在使用 Java Language Guide (v1.4) 中的这段代码

Retrieving a page by path

If you know the relative path of a page within the Google Site, you can use the path parameter to fetch that particular page. This example would return the page located at http://sites.google.com/site/siteName/path/to/the/page:

ContentQuery query = new ContentQuery(new URL(buildContentFeedUrl()));
query.setPath("/path/to/the/page");
ContentFeed contentFeed = client.getFeed(query, ContentFeed.class);
for (BaseContentEntry<?> entry : contentFeed.getEntries()) {
System.out.println(" title: " + entry.getTitle().getPlainText());
}

如果我使用客户端登录方法,一切正常。但是,当我使用 Oath(两条腿)时,我得到以下响应:

com.google.gdata.util.AuthenticationException: Token invalid - Invalid token:
<HTML>
<HEAD>
<TITLE>Token invalid - Invalid token: </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - Invalid token: </H1>
<H2>Error 401</H2>
</BODY>
</HTML>

这个版本工作正常:

SitesService client = new SitesService("Test");
client.setUserCredentials(USER_NAME, PASSWORD);

ContentQuery query = new ContentQuery(new URL(
"https://sites.google.com/feeds/content/" + DOMAIN + "/" + SITE_NAME + "/"));

query.setPath("/7D502A5D7080697F65F838D56C4C4A09");
ContentFeed contentFeed = client.getFeed(query, ContentFeed.class);
for (BaseContentEntry entry : contentFeed.getEntries()) {
System.out.println("Title: " + entry.getTitle().getPlainText());
}

这个版本抛出错误:

SitesService client = new SitesService("Test");
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setScope("https://sites.google.com/feeds/content/");
client.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());

ContentQuery query = new ContentQuery(new URL(
"https://sites.google.com/feeds/content/" + DOMAIN + "/" + SITE_NAME + "/"
+ "?xoauth_requestor_id=" + USER_NAME));


query.setPath("/7D502A5D7080697F65F838D56C4C4A09");
ContentFeed contentFeed = client.getFeed(query, ContentFeed.class);
for (BaseContentEntry entry : contentFeed.getEntries()) {
System.out.println("Title: " + entry.getTitle().getPlainText());
}

我还注意到,当我删除该行时:

query.setPath("/7D502A5D7080697F65F838D56C4C4A09");

错误没有抛出,但显然它会返回站点中的所有页面。

最佳答案

您的网站是公开的吗?或者您是否启用了页面级别权限,并且该特定页面的查看/编辑访问权限的人数有限?
可能是这个原因。

关于java - 使用 Oath 对 Google 网站中的 contentfeed 执行查询时 token 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9549549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com