0

I need to upload a video in .NET I use your client library. And when I receive code at my callback url, I need to change this code for token. How can I do this? I didn't find any information about this. And then, where should I put this token, uploading a video?

Thanks

1 Answers1

0

Just like other quickstart using Youtube API, you must also follow the steps on how to obtain your client_secret.json that contains your token_uri:

  • Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
  • On the Add credentials to your project page, click the Cancel button.
  • At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
  • Select the Credentials tab, click the Create credentials button and select OAuth client ID.
  • Select the application type Other, enter the name "YouTube Data API Quickstart", and click the Create button.
  • Click OK to dismiss the resulting dialog.
  • Click the download icon (Donwload JSON) button to the right of the client ID.
  • Move the downloaded file to your working directory and rename it client_secret.json.

client_secret.json

{"installed":{"client_id":"837380381682-kthu0nva0f5tqli35o6hk4jiv0p9mh3s.apps.googleusercontent.com","project_id":"sureness-1534400441179","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://www.googleapis.com/oauth2/v3/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"n-5X4ssSnqw9JXFOrLAl1J1y","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

This is a code snippet from .Net Code Sample where client_secrets.json was implemented:

 UserCredential credential;
  using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
  {
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        // This OAuth 2.0 access scope allows for full read/write access to the
        // authenticated user's account.
        new[] { YouTubeService.Scope.Youtube },
        "user",
        CancellationToken.None,
        new FileDataStore(this.GetType().ToString())
    );
  }
jess
  • 2,376
  • 1
  • 7
  • 23
  • after that there's the request at my callback. I receive code. What should I do then with that? I need to exchange this code for token. How can I do that? and then how can I use it in following requests? – Pavel Yakimovich Sep 25 '18 at 20:05
  • If you're referring to refreshed tokens, you can check this google documentation -> https://developers.google.com/identity/protocols/OAuth2WebServer#exchange-authorization-code regarding Exchange authorization code for refresh and access tokens. – jess Sep 26 '18 at 02:45
  • and where should I put this token in .NET library, when I want to upload video? – Pavel Yakimovich Sep 26 '18 at 08:10
  • Have you checked this related SO post? - https://stackoverflow.com/questions/7454930/google-api-how-can-i-use-refreshtokens-to-avoid-requesting-access-every-time-m – jess Sep 26 '18 at 08:41
  • Well, the problem is: When I call authorizeAsync. Redirect via browser occurs. I let give all the required permissions for this app. Then it makes request to callback (myapp/authorize). I receive code and with that code I can receive token. Then I should use this token in all following request. And I have no idea, how to create youTubeService object with this token instead credentials object (according to your documentation) – Pavel Yakimovich Sep 26 '18 at 09:25
  • when the method AuthorizeAsync is called, it just returns redirect, and the object credential is not filled with the data. – Pavel Yakimovich Sep 26 '18 at 12:41