how to upload data to google cloud storage using rest api - rest

I am trying to upload data to google cloud storage using rest api
According to the documentations we can use this api to send data to cloud store
https://www.googleapis.com/upload/storage/v1/b/[Bucket
name]/o?uploadType=media&name=[object name]
and sending auth,content-type and content-length as header
auth can be genereted using service accounts which i generated but still unable to upload the file
i am getting this error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}

one of the correct way to do it would be
https://www.googleapis.com/upload/storage/v1/b/[bucket_name]/o?key={your_key}&uploadType=media&name=happy3
you can generate key from api screen in google console
other way is to go to outh2.0 playground and send request from there
it will generate header files accordingly

Related

Cant access firebase storage console rules 403

I am having problems with firebase, i just recently started learning it. Im trying to setup my rules for firebase storage but it wont stop loading and i get error message 403 from the console. Full error message in JSON is:
{
"error": {
"code": 403,
"message": "Requests from referer \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_HTTP_REFERRER_BLOCKED",
"domain": "googleapis.com",
"metadata": {
"service": "firebaserules.googleapis.com",
"consumer": "projects/300182265570"
}
}
]
}
}`
I've tried to google for answers but I'm not any wiser on what to do.
Sidenote, i also get some error message when i try to upload files to my storage from my app about "Bucket not being properply set up".
But I can't even access the rules on firebase.console for storage.
Cheers!

Upload a image to Google Cloud Storage using Rest end point via API-KEY

I am new to Google Cloud. I want to upload an image to my Bucket.
I did it successfully from the GCP Console and GCP Shell. However, I am unable to do it using REST Endpoint using API-KEY.
Here is my URL.
https://www.googleapis.com/upload/storage/v1/b/[MY_BUCKET]/o?uploadType=media&name=myhero&key=[MY_API-KEY]
I am getting the following message
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Anonymous caller does not have storage.objects.create access to [MY_BUCKET]/myhero.",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Anonymous caller does not have storage.objects.create access to [MY_BUCKET]/myhero."
}
}
This is because the bucket currently does not allow any way to allow users with the API-KEY even though the API-KEY allows the user of this key to upload an object to the bucket.
What should I do
1) if I want to go with the API-key way.
2) if I want to go with service-account way. What is the best way to generate Authorisation token? I have come till this point
{"alg":"RS256","typ":"JWT"}.
{
"iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5#developer.gserviceaccount.com",
"scope":"https://www.googleapis.com/auth/prediction",
"aud":"https://www.googleapis.com/oauth2/v4/token",
"exp":1328554385,
"iat":1328550785
}.
But I am unable to generate {Base64url encoded signature} as I am unable to figure out the private and public keys...
You are getting “anonymous caller” because you are not properly authenticated. You can authenticate using a bearer token instead of the API-KEY.
You can run the following script:
BUCKET=<BUCKET_NAME>
OBJECT=<OBJECT>
TOKEN=$(gcloud auth print-access-token)
curl "https://www.googleapis.com/upload/storage/v1/b/$BUCKET/o?uploadType=media&name=$OBJECT" -H"Authorization: Bearer $TOKEN" -H'Content-Type: image/jpg' --data-binary #$OBJECT

Youtube analytics API Playlists filter returns Unknown error occurred on the server

When retrieving my playlists statistics using the Youtube Analytics API, quite often the API returns error 500
{
"error": {
"errors": [
{
"domain": "global",
"reason": "internalError",
"message": "Unknown error occurred on the server."
}
],
"code": 500,
"message": "Unknown error occurred on the server."
}
}
The request that I make is authorized, by turning on the Authorize requests using OAuth 2.0 in the api explorer
Here is a link to the API explorer, which is taken from the official documentation
Any ideas? Thank you!

Facebook Graph API Explorer won't delete a request

I'm trying to delete a request via Graph API Explorer. Request is generated by my mobile application. Of course, I use an access token from this application. And I've got the following error:
{
"error": {
"message": "(#2) Failed to delete any app request",
"type": "OAuthException",
"code": 2
}
}
The request exists, I can GET it.
The issue was that I tried to delete a request that didn't belong to me.

Google Cloud Storage : Google Cloud Storage JSON API to fix Access Not Configured error 403?

I am using an HTTP POST request to upload a file onto Google Cloud Storage.
Request is:
POST /upload/storage/v1beta1/b/myBucket/o?uploadType=media&name=testFile HTTP/1.1
Host: www.googleapis.com
Content-length: 24
Content-type: text/plain
Authorization: OAuth ba26.AHXXXXXXXXXVHXdVRAhBAHR_UXXXXXLV-MqPMXXXJwc
<BINARY DATA - 24B>
I am getting the following error as the response:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
Somewhere I read that I need to switch on Google Cloud Storage JSON API.
Is it compulsory to switch on Google Cloud Storage JSON API
or is there any other solution to fix this error?
To use the JSON API, it must be enabled. Enable the JSON API by visiting the Cloud Console, clicking APIs, and enabling the "Google Cloud Storage JSON API"