I have set up a new Project and Client ID for use by a new 'desktop' application, which now needs authorization. Actually, the 'desktop' application is a batch process on a headless Linux server in this case.
The OAuth 2.0 for Mobile & Desktop Apps guide is Google's official instruction for obtaining the necessary Access Token and Refresh Token that such an application needs. In step 2: send a request ... is the following text:
The value must exactly match one of the authorized redirect URIs for
the OAuth 2.0 client, which you configured in your client's API Console
Credentials page. If this value doesn't match an authorized URI, you will
get a redirect_uri_mismatch error.
However, when creating a Desktop client, there appears to be no place to specify a Redirect URI in the API Credentials page. I've created a Web Client credentials on the same Google Developer's Console page, and that allows for a Redirect URL, but I don't see that at all on the Desktop client.
How can I obtain the tokens necessary to continue? Is there some other setting that I must choose in order or the Redirect URI option to show up on Desktop Credentials, or am I misreading this, or ????
EDIT as requested
(... after creating a client and setting appropriate parameters...) when I execute this code...
$client->setRedirectUri('http://web.lovelady.com/google-api-php-client/examples/large-file-download.php')'
$authUrl = $client->createAuthUrl();
printf("Open this link in your browser:\n%s\n", $authUrl);
printf('Enter verification code: ');
$authCode = trim(fgets(STDIN));
The resultant link ends with the redirect_uri_mismatch error as stated.
If I omit that first line (setRedirectUri()), then the link works and authorization takes place, but after authorization and my approval, there is a "page cannot be displayed" error
Here is my sample for Google drive with php and a desktop app. Let me know if it helps
404 error
After checking your video. I am happy to say that this is working as intended. The 404 is a result of the fact that you do not have a web server running on your machine. but if you check the url bar you will find the code you are looking for
copy the code and place it in the app the console window and it should run.