1

i am trying to authorize a youtube data request (scope) using google sing in api. Google Sign In works perferct inside my app and i am getting logged in. How do I use the result of the google sign in api to send a request to a youtube data api scope?

My Sign In:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

This workes fine.

I get a GoogleSignInAccount and a GoogleApiClient from the result. How do I send a request to youtube for example to add a subscription or get the channel name/id?

Thanks

Keba

2
  • Really? How am I meant to release an app to the play store if google doesn´t want to explain there api to me? When can´t there be an easy way to just login a user and use a simple http request to e.g. subscribe to a channel?!? Commented Apr 29, 2017 at 17:25
  • 1
    all Oauth2 scopes require the authotise token. so if you send a request for something, you will need to send the token that you have received from the login. As to the "subscribe" button, I have noticed that you must be signed into your account on youtube itself, as it will redirect you there. Was not always so, but has changed. Commented May 1, 2017 at 13:15

1 Answer 1

4

ask Google is not able to work with/answer my question, I will now do it myself. (It´s a little embarrassing that a company like google is not able to help developers who ARE working with there apis.)

But thats what I got to work:

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope("https://www.googleapis.com/auth/youtube"))
            .requestIdToken("APIKEY FROM WEBSITE")
            .requestEmail()
            .build();
    api = new GoogleApiClient.Builder(main.getApplicationContext())
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    api.connect();

This will authorise the user, if you want android to show a login window:

Intent intent = Auth.GoogleSignInApi.getSignInIntent(api);
            main.startActivityForResult(intent, 9001);

The result can be used as following:

Account account = result.getSignInAccount().getAccount();

The Account can now be used to e.g. subscribe to somebody on youtube.

GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
            Main.main,
            Collections.singleton("https://www.googleapis.com/auth/youtube"));
    credential.setSelectedAccount(google.getAccount());
    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential)
            .setApplicationName("APPNAME")
            .build();

The youtube object can now be used for anything you like.

Thanks for this community, even when i am very disappointed about google.

Keba

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.