联系v3兼容性问题

时间:2015-02-10 08:05:44

标签: java oauth-2.0

我正在尝试使用oauth2进行身份验证和联系api以获取联系人等来自Gmail等所有用户联系人。但是我正在使用 Google API Client 1.14.1(beta)jar 的jar文件存在一些兼容性问题,并尝试使用 com.google.gdata-contacts-1.41.5.w1.jar 用于联系服务&联系供稿,但代码无法正常工作,并且不断提供内部服务器错误。如何解决这个问题?我怎么知道特定的jar文件是兼容的。

I am using code from this link

我点击按钮时给出的授权网址: - https://accounts.google.com/o/oauth2/auth?client_id=your_client_id_goes_here&redirect_uri=your_redirest_urls_goes_here&scope=https://www.google.com/m8/feeds/&response_type=code

 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    HttpTransport transport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    out.println("JACKSON :: "+jsonFactory);
    GoogleAuthorizationCodeTokenRequest authorizationTokenRequest = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, request.getParameter("code"), REDIRECT_URL);

    GoogleTokenResponse tokenResponse = authorizationTokenRequest.execute();

    out.println("OAuth2 Access Token: " + tokenResponse.getAccessToken());

    /*GoogleCredential gc = new GoogleCredential();
            gc.setAccessToken(tokenResponse.getAccessToken());
            out.println("gc :: "+gc);*/
    ContactsService contactsService = new ContactsService("Socioengg");
    //  Credential credential = exchangeCode(request.getParameter("code"));
    //contactsService.setOAuth2Credentials(credential);
    out.println("-------------------------------Hellloo::"+contactsService );
    contactsService.setAuthSubToken(tokenResponse.getAccessToken());

    out.println("Succeeded :: "+contactsService);

    try {
        URL feedUrl = new URL("https://www.google.com/m8/feeds/");

        Query myQuery = new Query(feedUrl);
        myQuery.setMaxResults(1000);

        ContactFeed resultFeed = contactsService.query(myQuery, ContactFeed.class);

        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
            out.println(resultFeed.getEntries().get(i).getTitle().getPlainText() + "<br/>");
        }

    } catch (Exception e) {
        System.out.println(e);
    }}

0 个答案:

没有答案