How to access firebase bucket in google cloud API - swift

I am working on google Speech to Text API. Where i am recording audio in iphone and saving it on Firebase bucket. than when i call api i get error 403.
curl -s -X POST -H "Content-Type: application/json" --data-binary #request.json \
"https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}"
content of request.json
{
"config": {
"encoding":"FLAC",
"languageCode": "en-US"
},
"audio": {
"uri":"gs://audiosave-9ec73.appspot.com/AudioFiles/audio.flac"
}
}
and response i am getting
{ "error": {
"code": 403,
"message": "Anonymous caller does not have storage.objects.get access to audiosave-9ec73.appspot.com/AudioFiles/audio.flac.",
"status": "PERMISSION_DENIED" } }

Related

Invalid story format failed to parse story while posting Rasa X Http API

I am trying to create a story using POST in Postman tool and below is my story format .
I am using below format because in GET request I got the story in the same format.
{
"id": 65,
"name": "interactive_story_65",
"story": "35 interactive_story_65\n* emp_info\n - utter_employee",
"annotation": {
"user": "me",
"time": 1597919151.8836874962
},
"filename": "data\\stories.md"
}
But, I am getting below error:
{
"version": "0.31.0",
"status": "failure",
"message": "Failed to parse story.",
"reason": "StoryParseError",
"details": "Invalid story format. Failed to parse '## {\r\n \"id\": 65,\r\n \"name\": \"interactive_story_65\",\r\n \"story\": \"## interactive_story_65\\n* emp_info\\n - utter_employee\",\r\n \"annotation\": {\r\n \"user\": \"me\",\r\n \"time\": 1597919151.8836874962\r\n },\r\n \"filename\": \"data\\\\stories.md\"\r\n }'",
"help": null,
"code": 400
}
Attached is below screenshot:
enter image description here
Please help.
This endpoint is actually expecting plain markdown, with text/x-markdown as the content-type header. If you look closely at the docs, you'll see that you're using the response schema as the request schema - I did that too at first. The request schema is just a markdown string e.g.
curl --request PUT \
--url http://localhost:5002/api/stories \
--header 'authorization: Bearer <Token>' \
--header 'content-type: text/x-markdown' \
--data '## greet
* greet
- utter_greet\n'

FireStore REST API: How to add a subcollection to a document using REST commands?

Using FireStore's REST API documented at: https://firebase.google.com/docs/firestore/reference/rest
I'm trying to create a new document in "users" that has a subcollection named "subcol1" with an empty doc in it called "subdoc1"
However, the following REST command to create the new document does not work:
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { 'subcol1': [{'subdoc1': { 'fields': {} } }] } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/users"
How does one add a subcollection to a new document (or existing one?) using FireStore's REST API?
I specifically have to use REST for this implementation.
This is the error response I get back:
{ "error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (Map), Cannot have repeated items ('subcol1') within a map.\nInvalid JSON payload received. Unknown name \"\" at 'document.fields[0].value': Proto fields must have a name.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (Map), Cannot have repeated items ('subcol1') within a map."
},
{
"field": "document.fields[0].value",
"description": "Invalid JSON payload received. Unknown name \"\" at 'document.fields[0].value': Proto fields must have a name."
}
]
}
] } }
Thanks!
After more tinkering with this, I found a solution.
The following works:
First create the new document (without the subcollection).
Next create the subdocument using the "not-yet-created" subcollection's URL.
So first create the new "top-level" doc:
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/users"
Then create the subdoc (which "creates" the subcollection):
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/
users/<USER-KEY-FROM-PREVIOUS-JSON-RESPONSE>/subcol1"

Google URL Shortner cURL returns error

I have a API Key and tried to use it for shortening URL. If I shorten google.com then I get shorten url
curl https://www.googleapis.com/urlshortener/v1/url?key=MYKEY -H 'Content-Type: application/json' -d '{"longUrl": "www.google.com"}'
{
"kind": "urlshortener#url",
"id": "shorten url",
"longUrl": "http://www.google.com/"
}
But if I use other URLs like yahoo.com then returns the error
curl https://www.googleapis.com/urlshortener/v1/url?key=MYKEY -H 'Content-Type: application/json' -d '{"longUrl": "www.yahoo.com"}'
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
Not sure why?

Ionic 2.0 push security profile not found error

I'm making android push service.
I enrolled security profile and add fcm server key and my keystore file
ionic security profiles list
name | tag | android | ios
skout90| skout90 | V |
And i requested below
curl -X POST -H "Authorization: Bearer my_api_key" -H "Content-Type:
application/json" -d '{
"tokens": ["my_device_key"],
"profile": "skout90",
"notification": {
"message": "Alert!"
}
}' "https://api.ionic.io/push/notifications"`
but
I got response
{
"meta": {
"request_id": "1b855552-195e-4dd3-cd36-ae49b19490a4",
"status": 400,
"version": "2.0.0-beta.0"
},
"error": {
"type": "BadRequest",
"link": null,
"message": "Security Profile 'skout90' not found."
}
}
I can't find what is wrong.
What do i have to?
please help me...
I solved this problem myself.
-H "Authorization: Bearer my_api_key"
I input wrong my_api_key.

Google Drive Rest Api Files export limitation

I use rest api "https://www.googleapis.com/drive/v3/files/fileId/export" "reference page" to get google Doc
I have document size ~ 5 MB when i try to get the file i had the json error :
{
"error": {
"errors": [
{
"domain": "global",
"reason": "exportSizeLimitExceeded",
"message": "This file is too large to be exported."
}
],
"code": 403,
"message": "This file is too large to be exported."
}
}
Is there any way to fix this error?
Instead of using this export endpoint you can request exportLinks field in the Files: list:
curl \
'https://www.googleapis.com/drive/v3/files/[FILE_ID]?fields=exportLinks' \
--header 'Authorization: Bearer [ACCESS_TOKEN]' \
--header 'Accept: application/json'
That will return something like this (these are links I got for a Google Slides presentation):
{
"exportLinks": {
"application/vnd.oasis.opendocument.presentation": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=odp",
"application/pdf": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=pdf",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=pptx",
"text/plain": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=txt"
}
}
And those urls don't have such a hard size limit (I was able to get out ~50mb PDFs)
As stated in the error message there is a limit to how big of a file the API can export. There is really nothing you can do to fix that your going to have to do it with smaller files.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "exportSizeLimitExceeded",
"message": "This file is too large to be exported."
}
],
"code": 403,
"message": "This file is too large to be exported."
}
}