5

我在这里搜索了一下,但找不到我的问题的答案。

我使用spring-sec-oAuth 2.0 (1.0.0.RC2a) 实现 oAuth 客户端。正确设置 beans.xml 后,我很高兴得到一个有效的令牌,一切看起来都很好。然后,我想使用日历 API——我不确定如何调用来获取日历对象。

我的(相关)设置:(spring-servlet.xml)

<!--apply the oauth client context-->
<oauth:client   id="oauth2ClientFilter" />

<oauth:resource id="google" 
    type="authorization_code" 
    client-id="<my client id>" 
    client-secret="<my client secret>"
    access-token-uri="https://accounts.google.com/o/oauth2/token" 
    user-authorization-uri="https://accounts.google.com/o/oauth2/auth"
    scope="https://www.googleapis.com/auth/calendar"
    client-authentication-scheme="form"
    pre-established-redirect-uri="https://ohad.sealdoc.com/oauth2-client/hello" />

<bean id="googleClientService" class="com...GoogleClientServiceImpl">
    <property name="butkeDemoRestTemplate">
        <oauth:rest-template resource="google" />
    </property>

和实现类:

public class GoogleClientServiceImpl implements DemoService 
{
    private RestOperations butkeDemoRestTemplate;

    @Override
    public String getTrustedMessage() 
    {
        String dataUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=writer";

        Calendar service = butkeDemoRestTemplate.getForObject(dataUri, Calendar.class);
        return "demo";
    }

}

这样做的结果是:

请求处理失败;嵌套异常是 error="invalid_request", error_description="{errors=[{domain=usageLimits, reason=accessNotConfigured, message=Access Not Configured}], code=403, message=Access Not Configured}"

毫无疑问,我在“getTrustedMessage()”中做错了,所以我听说要咨询专家……我确实想使用 OAuth2RestTemplate,但我怎么知道我应该使用的 URI?搜索(谷歌)后,我只找到了谷歌代码的例子,他们使用谷歌 oAuth(我不想使用 - 我宁愿为我的客户使用 Spring 实现)

有任何想法吗?

4

1 回答 1

3

知道了!

我已经解决了这个问题(得到“403,消息=访问未配置”的事情),只需在“服务”下的 Google API 控制台中启用特定服务......

于 2012-11-10T18:30:13.357 回答