1

I want to receive list of Youtube movies uploaded by user. To do this I need to use Youtube Data API Ver3 and make user authorization in Google API. To make authorization I want to use Google SignIn method instead of OAuth 2.0 method.

My Google SignIn code looks like this:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestScopes(new Scope("https://www.googleapis.com/auth/youtube.readonly")).requestIdToken(getString(R.string.default_web_client_id)).build();


    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .enableAutoManage(this, this)
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .build();

    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);

    GoogleSignInResult result = opr.get();

    GoogleSignInAccount acct = result.getSignInAccount();

    String idToke = acct.getIdToken();

I am receiving user idToken without any problems. How can I use idToken to make Google Api authorization. In Youtube Data Api documentation we can find many program examples. All examples using same authorization method:

   // This OAuth 2.0 access scope allows for read-only access to the
    // authenticated user's account, but not other types of account access.
    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly");

        // Authorize the request.
        Credential credential = Auth.authorize(scopes, "myuploads");

        // This object is used to make YouTube Data API requests.
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName(
                "youtube-cmdline-myuploads-sample").build();

        // Call the API's channels.list method to retrieve the
        // resource that represents the authenticated user's channel.
        // In the API response, only include channel information needed for
        // this use case. The channel's contentDetails part contains
        // playlist IDs relevant to the channel, including the ID for the
        // list that contains videos uploaded to the channel.
        YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
        channelRequest.setMine(true);
        channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
        ChannelListResponse channelResult = channelRequest.execute();

How can I use user idToken from my app to

  • Receive credential
  • Auth object
  • Auth.HTTP_TRANSPORT
  • Auth.JSON_FACTORY
kamito
  • 11
  • 2
  • Possible duplicate of [Retrieve Google Access Token after authenticated using Firebase Authentication](http://stackoverflow.com/questions/40838154/retrieve-google-access-token-after-authenticated-using-firebase-authentication) – GroovyDotCom Mar 22 '17 at 22:22
  • did you find solution? – Abdel Nov 03 '18 at 16:10

0 Answers0