Api response gives generic response - google-apis-explorer

I am trying to generate a oauth token for a service account on google. I am getting a generic response
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
I am not sure which field is invalid https://cloud.google.com/iam/credentials/reference/rest/v1/projects.serviceAccounts/generateAccessToken
I followed the steps in this url https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials
Any help would be really appreciated.

Related

Google Drive API v3: how to set canCopy capabilities on a file

I want to limit the capabilities of a file in personal Google Drive. When I use the API explorer Google Drive v3 API with the following request:
POST https://www.googleapis.com/drive/v3/files?key={YOUR_API_KEY}
{
"capabilities": {
"canCopy": false
},
"name": "testfile"
}
I get the following response:
403
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "fieldNotWritable",
"message": "The resource body includes fields which are not directly writable."
}
],
"code": 403,
"message": "The resource body includes fields which are not directly writable."
}
}
Which is the same response that I get when trying to update a file with:
PATCH https://www.googleapis.com/drive/v3/files/FileIdHere?key={YOUR_API_KEY}
{
"capabilities": {
"canCopy": false
}
}
It seems that there are no methods to accomplish this or has anyone a workaround?
If you check file resource you will notice that some fields are writeable while others are not.
The message you are seeing is because the field you are trying to set is not writeable this means you can not change it from the API

Error while accessing oneDrive: User's mysite not found

I'm trying to access oneDrive via Graph api, and when I hit the api, I get User's mysite not found.
GET https://graph.microsoft.com/beta/me/drive
{
"error": {
"code": "ResourceNotFound",
"message": "User's mysite not found.",
"innerError": {
"request-id": "13eb583d-c29a-42af-8868-bae06d554538",
"date": "2018-05-18T06:06:55"
}
}
}
So, looking out for the solution, I saw an issue where they said to get OneDrive for Business' location, But this returns UnauthorizedAccessException
GET https://graph.microsoft.com/beta/me?select=mySite
{
"error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message":
"Access denied. You do not have permission to perform this action or access this resource.",
"innerError": {
"request-id": "3489894e-faa0-42c6-9f3b-e76c4708ce15",
"date": "2018-05-18T06:10:00"
}
}
}
And when I hit for /me endpoint, there I see an empty array for provisionedPlans.
GET https://graph.microsoft.com/beta/me
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users/$entity",
"id": "7e8397a6-b299-34a2-af06-d3487t5b5174",
//...
"onPremisesProvisioningErrors": [],
"provisionedPlans": []
}
My access token is
eyJ0eXAiOiJKV1QiLCJub25jZSI6IkFRQUJBQUFBQUFEWDhHQ2k2SnM2U0s4MlRzRDJQYjdySGc5dDJ4SmxkODFMRURNY1FuN3pMYVgyektLaDR2SF9FSFltd1JaQ3Y5TU55VDJOR250VmlDQVFmTXpiTWxoYkZWQ19nSEdtaWhfWlJfcVlpaGRyMHlBQSIsImFsZyI6IlJTMjU2IiwieDV0IjoiaUJqTDFSY3F6aGl5NGZweEl4ZFpxb2hNMllrIiwia2lkIjoiaUJqTDFSY3F6aGl5NGZweEl4ZFpxb2hNMllrIn0.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvM2FjMThiOGMtNjY4ZC00NzBhLWJhMDctYWU0MjdlMTkwZGEyLyIsImlhdCI6MTUyNzE0MDg2MCwibmJmIjoxNTI3MTQwODYwLCJleHAiOjE1MjcxNDQ3NjAsImFjciI6IjEiLCJhaW8iOiJBVFFBeS84SEFBQUE4UitBY2U4bnpGU0JXRGg4NUFHUWE1VXowT05yZEZ5VzhXQnYvZ1BnVE1nMWx4MnNibkZSbUdrbHVsNVhiME5SIiwiYWx0c2VjaWQiOiI1OjoxMDAzMDAwMDk3NURDNEFCIiwiYW1yIjpbInB3ZCJdLCJhcHBfZGlzcGxheW5hbWUiOiJJbnRlbGlOb3Rpb24gRGVtbyIsImFwcGlkIjoiYWU0OTY3MGItNmIwYi00NjgxLWE5OTAtNmZmZWQ1NTFiMjMwIiwiYXBwaWRhY3IiOiIxIiwiZW1haWwiOiJrb21hbC5oZW5kcmVAcmF5a29yLmNvbSIsImZhbWlseV9uYW1lIjoiSGVuZHJlIiwiZ2l2ZW5f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mZivBg
Can't figure out that it is a access problem or provisioning problem. Can anyone suggest what's going wrong here.

REST API JSON error code and error message

I have been writing Web Services from a recent past, this is a sample success and error response.
error
{
"code": 1150,
"status": false,
"message": "API Student does not exist.",
"serverTime": "2013-11-29 09:47:52"
}
success
{
"code": 200,
"status": true,
"data": {
"id": 49
},
"serverTime": "2014-04-17 05:06:17"
}
With regards to returning errors I have a confusion, why do we always return one error code and one message, for example, when username and password is required as input params, say a blank request is made, so what I return is a error code 1100 and error message "Username is incorrect". I never return the whole list of errors, for example, in this case, two error message with two error codes should be sent so it saves end users data & time.
This is a sample of what I suggest?
{
"code": 1010,
"status": false,
"errors": [
{
"code": 1000,
"name": "Username invalid"
},
{
"code": 1001,
"name": "Password invalid"
},
{
"code": 1002,
"name": "Password not strong"
}
],
"serverTime": "2013-12-03 12:34:02"
}
Why is this not a good way to do? I have not seen this in either Twitter API or Facebook API.
Nobody can stop API designers to return multiple possible error responses. Decision is up to them only but in my opinion you should return most relevant error occurred from server side.
There can be many reasons behind it like below :
Unified Error Handling by all clients.
Most relevant error caused will help client more actually as he will not have to take care about all probabilistic error caused.
JSON structure simplicity. ( Error Array will be avoided. )

drive api bad request 400 when creating a form file

I am trying to create a new form with drive api and I am getting bad request response, anyone knows what is missing here? I think mimeType and Title should be enough, any thoughts?
Request
POST https://www.googleapis.com/drive/v2/files?key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.1.AADtN_UCYtStTpi_L_pjYdzUegofa6dVQMnEYY06Z39eZWYlMym8wnZu2j3ndsIagg
X-JavaScript-User-Agent: Google APIs Explorer
{
"mimeType": "application/vnd.google-apps.form",
"title": "fff.form"
}
Response
400 Bad Request
Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}

Get file information through api

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