I'm trying to run the following code:
var oAuthConfig = UrlFetchApp.addOAuthService("name");
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/admin.directory.user");
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("******************");
oAuthConfig.setConsumerSecret("******************");
var options =
{
"oAuthServiceName" : "name",
"oAuthUseToken" : "always",
};
var result = UrlFetchApp.fetch("https://www.googleapis.com/admin/directory/v1/users?domain=******************&maxResults=2",options);
}
I'm sure I'm using the "secret key" and "consumer key" right.
The error is:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console" }
]
,
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." }
}
Anyone know how to fix it?
You need to send the Auth Token as parameter in the UrlFetchApp.fetch .
As you didn't send it the message of unauthenticated was sent.
Related
I encountered this Error and i don't known how to resolve this :
2023-02-07 18:11:17.699 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/Draft/DownloadFileInDrive FAILED.
Reason:
com.google.api.client.http.HttpResponseException: 403 Forbidden
GET https://www.googleapis.com/drive/v3/files/1lXeG5nWa9uPyPqSPUQKYrVch7JiQvcjBtOMbohieick?alt=media
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"errors": [
{
"message": "Insufficient Permission",
"domain": "global",
"reason": "insufficientPermissions"
}
],
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",
"domain": "googleapis.com",
"metadata": {
"service": "drive.googleapis.com",
"method": "google.apps.drive.v3.DriveFiles.Get"
}
The error is displayed because of this line and does not go further :
FileList result = service.files().list().setPageSize(10).setFields("nextPageToken, files(id, name)").execute();
Could you tell me what's wrong?
Can someone tell me if a forum for Google drive API exists?
Thanks you
I want to get all my groups but I am not an admin
I know how to fetch groups if I am admin. But if not - I don't understand. Also I can see its via website
My steps:
I do auth with Google and with scope
[
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/groups",
]
I fetch groups by GET. Url: "https://admin.googleapis.com/admin/directory/v1/groups?domain=konstructly.com"
I get the next problem:
{
"error": {
"code": 403,
"message": "Not Authorized to access this resource/api",
"errors": [
{
"message": "Not Authorized to access this resource/api",
"domain": "global",
"reason": "forbidden"
}
]
}
}
My question
How can I get my Google Groups via Google API?
I tried:
Auth with scope
[
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/groups",
]
GET "https://admin.googleapis.com/admin/directory/v1/groups?domain=konstructly.com"
Expectation:
List of my groups
Actual result:
{
"error": {
"code": 403,
"message": "Not Authorized to access this resource/api",
"errors": [
{
"message": "Not Authorized to access this resource/api",
"domain": "global",
"reason": "forbidden"
}
]
}
}
Instead of using the Google Workspace Admin SDK, use the Groups Service from Google Apps Script, more specifically GroupsApp.getGroups()
According to https://developers.google.com/drive/api/v3/reference/changes/watch,
you need an https address to make it works if you need to watch over a change of resources.
I've configured the domain successfully by going to Google Cloud Console > Domain Verification > Add Domain.
Then I use Postman to make a call to test it:
https://www.googleapis.com/drive/v3/changes/watch?pageToken=nextPageToken
{
// "kind": "api#channel",
"id": "1234231",
"expiration": 1656402233000,
"type": "webhook",
"payload": true,
"address": "https://mrnoc.blogspot.com",
"params": {
"pageToken": "nextPageToken"
}
}
However, it failed and generated this error message:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://mrnoc.blogspot.com"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://mrnoc.blogspot.com"
}
}
I have no idea how it doesn't work, I've tried to look around but it a dead end as it seems like I've configured everything properly.
Please help if you know what might stop it from working.
Thank you
Building a Chrome Extension for Gmail, trying to use Chrome Auth to gain access to gmail api per this StackOverflow post and the Gmail API docs, among others. I successfully receive the token with chrome.identity.getAuthToken({ 'interactive': true }, function(token) {} however when I plug the token into the request url I get the following 401 error response (code follows)
error response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
My code:
background.js
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
thisToken = token
chrome.runtime.onMessage.addListener(
function(request,sender,sendResponse){
var gapiRequestUrlAndToken = "https://www.googleapis.com/gmail/v1/users/mail%40gmail.com/threads?key={" + thisToken + "}"
var makeGetRequest = function (gapiRequestURL)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", gapiRequestURL, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
makeGetRequest(gapiRequestUrlAndToken);
}
);
});
}
})
manifest.json
{
"manifest_version": 2,
"key": "<key>",
"name": "exampleName",
"description": "Description",
"version": "0.0.1.7",
"default locale": "en",
"icons": { "128": "imgs/pledge_pin.png"},
"content_scripts" : [
{
"matches": ["*://mail.google.com/mail/*"],
"js": ["js/jquery.js", "js/compose.js", "bower_components/jqnotifybar/jquery.notifyBar.js"],
"css": ["css/stylesheet.css", "bower_components/jqnotifybar/css/jquery.notifyBar.css"]
}
],
"background": {
"scripts": ["scripts/background.js"]
},
"permissions": [
"identity"
],
"oauth2": {
"client_id": "<client id>",
"scopes": ["https://www.googleapis.com/auth/gmail.modify"]
}
}
I suspect it has something to do with the fact that I'm trying to use Chrome Auth for Gmail api, but other posts I've read have lead me to believe this is a viable option.
In case my code didn't give it away, I'm a newbie, so any help is most welcome, and I greatly appreciate your time.
key is for generic application secrets. For user specific tokens you need to use access_token. And token should not be wrapped in {}. If mail%40gmail.com is the actual value you are using in the URL, it won't work. It either needs to be the email address of the authenticated user or me.
So change:
"https://www.googleapis.com/gmail/v1/users/mail%40gmail.com/threads?key={" + thisToken + "}"
To this:
"https://www.googleapis.com/gmail/v1/users/me/threads?access_token=" + thisToken
I'm not able to get information about a file.
Here it is my situation:
I'm logged in google drive
Through google picker I get the file ID
Then I type the url https://www.googleapis.com/drive/v1/files/[file ID]
But I get the following error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit Exceeded. Please sign up"
}
}
How can I sort it out?
You can't retrieve the file metadata by typing the url in your browser.
Instead you need to send an authorized request with a valid OAuth 2.0 token.
For more information:
https://developers.google.com/drive/about_auth