5
$\begingroup$

I have been using the Youtube Data API v3 for sometime without any issue using HTTPRequest to send request by using Google API Key and URLRead to get the response in Mathematica. But for certain Youtube Data, Google requires OAuth 2.0 Authentication instead of a basic API Key. So I created the credentials online and got the client_secret.json file. Which contains:

{"installed":{
"client_id":"xxx.apps.googleusercontent.com",
"project_id":"xxx",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"xxx",
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
}}

All I want is to run the Mathematica's OAuth 2.0 feature to get the token to put in my endpoint URL when sending requests. How do I do that? I can't find anything in documentation in version 12. Maybe it is hidden in some context that I don't know.

Also I want the scope to be "https://www.googleapis.com/auth/youtube".


Looking at Can anyone explain how to use Mathematica's OAuth package?, I have tried the following:

token=OAuthSigning`OAuthAuthentication[
    "OAuthVersion"->"2.0",
    "AuthorizeEndpoint"->credentials["auth_uri"],
    "AccessEndpoint"->credentials["auth_provider_x509_cert_url"],
    "RedirectURI"->First[credentials["redirect_uris"]],
    "ConsumerKey"->credentials["client_id"],
    "ConsumerSecret"->credentials["client_secret"](*,
    "RequestEndpoint"->credentials["token_uri"]*)
]

where

credentials=Import[FileNameJoin[{NotebookDirectory[],"client_secret.json"}],"RawJSON"]["installed"]//Dataset

But it opens up the authentication dialog box with link to get the authentication code. On clicking the link, it gives me the following error:

400. That’s an error.

Error: invalid_request

Missing required parameter: scope

So my question is How do I give the scope parameter to the OAuthSigning`OAuthAuthentication function?

$\endgroup$
  • 1
    $\begingroup$ There's no great way to do this without making a full service connection. You can check out how I did that for YouTube here. $\endgroup$ – b3m2a1 Jun 18 '19 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.