Open rgrzywinski opened 3 years ago
Thanks for bringing this to our attention!
It turns out this is an authentication issue - this API seems to only accept API keys. To generate an API key, see https://developers.google.com/webmaster-tools/search-console-api/v1/configure
The sample code you'll want to run is something like:
import {google} from 'googleapis';
const searchconsole = google.searchconsole('v1');
async function main() {
const apiKey = "your-key-goes-here";
// Make the request with an API key
const res = await searchconsole.urlTestingTools.mobileFriendlyTest.run({
// Request body metadata
requestBody: {
"requestScreenshot": false,
"url": "https://google.com/"
},
key: apiKey,
});
console.log(res.data);
}
main().catch(e => {
console.error(e);
throw e;
});
Note that the authentication option was changed to an URL query parameter key
.
We will still need to fix the underlying sample code.
Thanks again. Feel free to close as you deem necessary.
I am getting this error in my nest js application. Any idea?
Error: Not Found
at Gaxios._request (D:\Nest Js projects\Sharepoint\sharepoint\node_modules\gaxios\src\gaxios.ts:169:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at JWT.requestAsync (D:\Nest Js projects\Sharepoint\sharepoint\node_modules\google-auth-library\build\src\auth\oauth2client.js:382:18)
at Upload.makeRequest (D:\Nest Js projects\Sharepoint\sharepoint\node_modules\@google-cloud\storage\build\src\resumable-upload.js:624:21)
at retry.retries (D:\Nest Js projects\Sharepoint\sharepoint\node_modules\@google-cloud\storage\build\src\resumable-upload.js:344:29)
at Upload.createURIAsync (D:\Nest Js projects\Sharepoint\sharepoint\node_modules\@google-cloud\storage\build\src\resumable-upload.js:341:21)
Environment details
googleapis
version: 71.0.0Steps to reproduce
Node's "searchconsole.urlTestingTools.mobileFriendlyTest.run()" API is throwing "GaxiosError: Request contains an invalid argument." We are using the API via a (Firebase) Cloud Function (both Node v10 nor Node 14 have the same result):
Our code exactly matches https://github.com/googleapis/google-api-nodejs-client/blob/master/src/apis/searchconsole/v1.ts#L1693 with the only difference being that we're using TypeScript (so the import is:
import { google } from 'googleapis';
).The following will fail:
But replacing it with:
const result = await searchConsoleAPI.sites.list({});
and adding in the necessary scope does not produce an error (i.e. I don't think that this is a permission problem especially since we also use other Google API's such as Sheets without any problems).