oauth 2.0 gwt访问令牌和谷歌日历api [英] oauth 2.0 gwt access token and google calendar api

查看:353
本文介绍了oauth 2.0 gwt访问令牌和谷歌日历api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了这个客户端库 https://code.google.com/p/gwt-oauth2/ 以获取我可以用来访问Google日历API的访问令牌。



在做了一些调查之后,我注意到另一个客户端库 http://code.google.com/p/gwt-google-apis/source/browse /trunk/apis/samples/calendar/com/google/api/gwt/samples/calendar/client/CalendarEntryPoint.java ,我可以使用它来制作Google日历API调用。



现在我不明白的是如何将两者结合起来。所以我现在有一个访问令牌,但第二个客户端库的示例代码不会在任何地方使用该访问令牌(它只使用来自谷歌API控制台的client_id和api_key)。



这两个库是相互排斥的还是它们要一起工作的?

编辑:



我想要实现的是授权我的应用程序使用第一个库访问Google日历,并使用第二个库调用API调用。问题是,当我使用第二个库进行API调用时,它不能识别出我的应用程序已被授权使用Google日历,我相信麻烦在于示例代码中的这一行:

  calendar.initialize(new SimpleEventBus(),
new GoogleApiRequestTransport(APPLICATION_NAME,API_KEY));

进行此调用时,它会注册第二个应用程序(我可以从我的第三方应用程序在我的谷歌帐户)。即使第一个应用程序已被授权使用Google日历,但新注册的应用程序仍希望再次获得授权。



因此,我环顾四周,看看是否有GoogleApiRequestTransport可以使用现有的应用程序,并且我设法找到了这个: http://gwt-google-apis.googlecode.com/svn-history/r1914/trunk/apis/javadoc/latest/javadoc/com/ google / api / gwt / shared / GoogleApiRequestTransport.html

这个GoogleApiRequestTransport允许我设置访问令牌(这正是我想要的)。但它已被弃用。所以我不知道该怎么做。

解决方案

存在。您指出的第二个库实际上也进行了Oauth2身份验证。在这个代码块中(从第75行开始):

  private void login(){
OAuth2Login.get() .authorize(CLIENT_ID,CalendarAuthScope.CALENDAR,
new Callback< Void,Exception>(){
@Override
public void onSuccess(Void v){
getCalendarId();
}
@Override
public void onFailure(Exception e){
GWT.log(Auth failed:,e);
}
}) ;
}

您可以看到对 OAuth2Login.get ).authorize(),这个过程将生成一个访问令牌,类似于您在第一个库中看到的一样(同样,我对Java的熟悉度也限制了我的实用性)。长话短说,看起来相同的Oauth2进程仍在实施,所以要回答你原来的问题,这两个库基本上是两种完成相同事情的方式 - 第一个只处理Oauth2交互,但第二个提供了一个完整的包与API自身进行交互。


I'm treading in unfamiliar territory again.

I used this client library https://code.google.com/p/gwt-oauth2/ to get an access token that I can use to access google calendar API.

After doing some research, I noticed another client library http://code.google.com/p/gwt-google-apis/source/browse/trunk/apis/samples/calendar/com/google/api/gwt/samples/calendar/client/CalendarEntryPoint.java that I can use to make google calendar api calls.

Now what I don't understand is how to combine the two. So I have an access token now, but the sample code from the second client library does not use that access token anywhere (it only uses the client_id and api_key from the google api console).

Are these two libraries mutually exclusive or are they meant to work together?

EDIT:

What I want to achieve is to authorize my application's access to Google calendars using the first library, and make API calls using the second. The trouble is, when I make API calls with the second library, it doesn't recognize that my application is already authorized to use Google Calendars, I believe the trouble is with this line from the sample code:

calendar.initialize(new SimpleEventBus(),
    new GoogleApiRequestTransport(APPLICATION_NAME, API_KEY));

When this call is made, it registers a second application (I can see this from my third party apps in my google account). Even though the first application is already authorized to use Google calendars, the newly registered application wants to be authorized again.

So I looked around to see if there is a GoogleApiRequestTransport that can use an existing application, and I managed to find this: http://gwt-google-apis.googlecode.com/svn-history/r1914/trunk/apis/javadoc/latest/javadoc/com/google/api/gwt/shared/GoogleApiRequestTransport.html

This GoogleApiRequestTransport lets me set the access token (which is what I wanted in the first place). But it is a deprecated. So I don't know what to make of it.

解决方案

I'll preface this by saying my Java knowledge is non-existent. The second library you point out actually does Oauth2 authentication as well. In this code block (starting at line 75):

private void login() {
  OAuth2Login.get().authorize(CLIENT_ID, CalendarAuthScope.CALENDAR,
      new Callback<Void, Exception>() {
        @Override
        public void onSuccess(Void v) {
          getCalendarId();
        }
        @Override
        public void onFailure(Exception e) {
          GWT.log("Auth failed:", e);
        }
      });
}

You can see a call to OAuth2Login.get().authorize(), which is the process that will generate an access token similar to what you saw with the first library (again, my familiarity with Java is limiting my utility here). Long story short, it appears that the same Oauth2 process is still being implemented, so to answer your original question, these two libraries are basically two ways of accomplishing the same thing - the first just handles the Oauth2 interaction, but the second provides a full package to interact with the APIs themselves.

这篇关于oauth 2.0 gwt访问令牌和谷歌日历api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆