emran396 / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

jars are not supporting for this code pls send me the the supporting code sample with jars for java #765

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
package com.epro.Google;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import 
com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResour
ce;
import 
com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestU
rl;
import 
com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.Go
ogleAuthorizationCodeGrant;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.plus.Plus;
import com.google.api.services.plus.model.Person;
import com.google.api.client.repackaged.com.google.common.base.Preconditions.*;

public class GoogleProfileAuthen {

//  private static final String SCOPE = 
"https://www.googleapis.com/auth/urlshortener";
    private static final String SCOPE = "https://www.googleapis.com/auth/userinfo.profile";
    private static final String CALLBACK_URL = "https://localhost:8088/GoogleProject/";
    //    private static final HttpTransport TRANSPORT = new NetHttpTransport();
    private static final HttpTransport TRANSPORT = new NetHttpTransport();
    private static final JsonFactory JSON_FACTORY = new JacksonFactory();

    // FILL THESE IN WITH YOUR VALUES FROM THE API CONSOLE
    //    private static final String CLIENT_ID = "<REPLACE ME>";
    //    private static final String CLIENT_SECRET = "<REPLACE ME TOO!>";

    private static final String CLIENT_ID = "1077929481400.apps.googleusercontent.com";
    private static final String CLIENT_SECRET = "Is-Ml9Wn1YKvgH8wOznv3HlA";

    public static void main(String[] args) throws IOException {
        // Generate the URL to which we will direct users
        System.out.println("TRANSPORT:::"+TRANSPORT);
        System.out.println("");
        String authorizeUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID,CALLBACK_URL, SCOPE).build();
        System.out.println("Paste this url in your browser: " + authorizeUrl);

        // Wait for the authorization code
        System.out.println("Type the code you received here: ");
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String authorizationCode = in.readLine();

        System.out.println("After pasted::::"+authorizationCode);
        // Exchange for an access and refresh token
        GoogleAuthorizationCodeGrant authRequest = new GoogleAuthorizationCodeGrant(TRANSPORT,
                JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, authorizationCode, CALLBACK_URL);
        authRequest.useBasicAuthorization = false;

        System.out.println("After authRequest::::");

        AccessTokenResponse authResponse = authRequest.execute();

        System.out.println("After authResponse::::");

        String accessToken = authResponse.accessToken;

        System.out.println("accessToken::::"+accessToken);
        System.out.println("TRANSPORT::::"+TRANSPORT);
        System.out.println("JSON_FACTORY::::"+JSON_FACTORY);
        System.out.println("authResponse.refreshToken::::"+authResponse.refreshToken);

//
//              GoogleAccessProtectedResource access = new 
GoogleAccessProtectedResource(accessToken,
//                  TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, 
authResponse.refreshToken);
        GoogleAccessProtectedResource requestInitializer = new GoogleAccessProtectedResource(accessToken,
                TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, "3600");

        System.out.println("access:::"+requestInitializer);

        //HttpRequestFactory rf = TRANSPORT.createRequestFactory(requestInitializer);

        //System.out.println("Access token: " + authResponse.accessToken);

        // Make an authenticated request
//      GenericUrl shortenEndpoint = new 
GenericUrl("https://www.googleapis.com/urlshortener/v1/url");
        System.out.println("requestInitializer:::"+requestInitializer.getClientId());
        Plus plus = new Plus(TRANSPORT, JSON_FACTORY,requestInitializer);
//      Plus plus = new Plus(TRANSPORT, requestInitializer,JSON_FACTORY);
        System.out.println("plus::"+plus);
//      Person profile = plus.people.get("me").execute();
        Person profile = plus.people().get("me").execute();
        System.out.println("ID: " + profile.getId());
        System.out.println("Name: " + profile.getDisplayName());
        System.out.println("Profile URL: " + profile.getUrl());

    }

}

Original issue reported on code.google.com by basith.smart@gmail.com on 4 Apr 2013 at 10:39

GoogleCodeExporter commented 9 years ago
For personal assistance with your code, please feel free to ask a question on 
www.stackoverflow.com using the tag [google-api-java-client]. At this time, 
there appear to be no problems with the jars in the library, so this issue is 
being closed.

Please, never post your client secret online. I strongly recommend you go to 
the API Console and delete the Client ID posted in the code above.

Also note that the oauth2.draft10 package has since been removed, since the 
OAuth2 final standard is well established and should be used instead.

Original comment by ngmic...@google.com on 4 Apr 2013 at 1:53

GoogleCodeExporter commented 9 years ago
hi, thank  you very much for your response,
pls specify the import which i need for this code.i need supported jars for 
this code
pls send the sample project code for login with jars to my email,
pls help me

Original comment by basith.smart@gmail.com on 5 Apr 2013 at 3:47