How to make a basic HTTP request with API key in Google Translate API v2? - rest

I want to make a translation with Google Translate API v2 with a basic HTTP request. I get an API key from the console but I can't find out how to use arguments to make the translation.
Note: I want it to autodetect the source language and I only want to choose the target language.
This is the URL that I tried to use:
https://translation.googleapis.com/language/translate/v2/detect?fields=detections&key=BIzaSyA8uHGnsA8ICcBWWJcxhqVePGFMq0L4u0g&q=grapes&target=es
It returns this:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}

See the documentation.
The authentication token goes in the Authorization request header, not the query string.

Related

How do I call create permissions on Google Drive API via Delphi

I'm trying to use Delphi to call Google Drive Permissions API to create a permission on a team drive. All goes well with the setting on the Google Try It section, but my Delphi code isn't working.
reqPermissions.Body.Add('{role: "organizer",type: "user",emailAddress: "it_admin#mycompany.com"}');
I've tried supplying the type field as a parameter in the Request component, but this also doesn't work. Driving me nuts at the mo, so any help much appreciated.
I always get the following response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "The permission type field is required.",
"locationType": "other",
"location": "permission.type"
}
],
"code": 400,
"message": "The permission type field is required."
}
}

Facebook Graph API - How to get scheduler post's all detail in graph API

I'm new in facebook graph API, I want to get all the details of scheduler post like
full_picture
message
etc
I used :
GET v4.0/...?fields={fieldname_of_type_ScheduledPost} HTTP/1.1
Host: graph.facebook.com
But, I got error :
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: ...",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "A-aQAYXFbAdSX7oMYfcUP_3"
}
}
Ref., https://developers.facebook.com/docs/graph-api/reference/scheduled-post/
The brackets and dots are just placeholders.
Wrong
fields={id,message,...}
Correct
fields=id,message,...
Also, you have to use the ID of a scheduled post instead of just using "..." in the API call.
To get all scheduled posts, use this endpoint: https://developers.facebook.com/docs/graph-api/reference/page/scheduled_posts/
Example:
/me/scheduled_posts?fields=id,message&access_token=<your-page-token>

Facebook's Batch Request not picking up a JSON parameter

My goal is to create a number of ads using Facebook's Batch API : https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.9
I am sending a POST request at this URL:
https://graph.facebook.com/v2.9/act_158365238/ads
I am sending 2 parameters as per the documentation:
1- access_token
2- batch
The JSON in the batch parameter looks like :
{
"method": "POST",
"relative_url": "v2.9\/act_158365238\/ads",
"attached_files": "test1",
"body": "creative={\"title\":\"Test title 1\",\"body\":\"Test body 1\",\"object_url\":\"https:\/\/apps.facebook.com\/testapp\/\", \"image_file\":\"test1.jpg\"}&targeting={\"countries\":[\"US\"]}&name=test1"
}
The Problem
When I send this request with POSTman or my PHP code, it throws the following error
{
"error": {
"message": "(#100) The parameter creative is required",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Gj2sG7N8l1f"
}
}
However when I send the exact same request via Facebook's Graph API tool, it successfully creates the ads.
According to the API Documentation provided to create creatives you should be posting to the URL "v2.9/act_187687683/adcreatives"... The fragment of the batch that you are showing is used to create an Ad.
If, as you say, your intention is to create an AdCreative then you should be using something like the above, which differs in the body from what you are using:
{
"method": "POST",
"name": "create_creative",
"relative_url": "v2.9/act_187687683/adcreatives",
"attached_files": "test1",
"body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
}
In the other hand, if what you are creating is an add, then you should consider referencing the AdCreative by its ID as is done in the examples, hence in the case of a creative added in the same batch you could use the relative reference to the name:
creative={\"creative_id\":\"{result=create_creative:$.id}\"}
or if it is a creative already created you can reference it by the creative_id:
creative={\"creative_id\":\"123456\"}
I think the message is a red herring -- it's not seeing your body's creative field because the OAuth isn't properly set in your POSTman requests, so it isn't parsing the body or seeing the creative field.
If you don't know how to set OAuth in POSTman, here's a good tutorial:
https://docs.brightcove.com/en/video-cloud/concepts/postman/postman.html

Google Container Engine REST API Authorization

As mentioned here I created API key for using cluster operations.
For example for this query:
https://www.googleapis.com/container/v1beta1/projects/PROJECT_ID/clusters
And as mentioned
After you have an API key, your application can append the query
parameter key=yourAPIKey to all request URLs.
I added it to url:
https://www.googleapis.com/container/v1beta1/projects/PROJECT_ID/clusters?key=my_key
But i have error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
I even tried to add key to Authorization part of header...and had this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Where is problem? Or did i something wrong?
According to the Google help documentation for API Keys (emphasis added):
An API key (either a server key or a browser key) is a unique
identifier that you generate using the Developers Console. Using an
API key does not require user action or consent. API keys do not grant
access to any account information, and are not used for
authorization.
Furthermore, it says that they can be used to access data that is public or owned by a Google service. The Google Container Clusters (GKE) data is neither of these. I'm not sure why the documentation suggests using an API key, but I know that OAuth works so if you can use that instead you should be able to get the REST API working.

Error creating Facebook test user

I am following the instructions at http://developers.facebook.com/docs/test_users/
When I do:
https://graph.facebook.com/APP_ID/accounts/test-users?
installed=true
&name=Fred
&locale=en_US
&permissions=read_stream
&method=post
&access_token=XXXXXXXXX
I get:
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: APP_ID",
"type": "OAuthException",
"code": 803
}
}
How do I fix this?
The issue is that you are using the string APP_ID instead of your app's id.
Further Explanation
I was able to duplicate the bug myself with the following steps:
Getting a App Access Token:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials
where YOUR_APP_ID and YOUR_APP_SECRET were replaced with the correct values from https://developers.facebook.com/apps
Using the provided access token, appending it to the url.
https://graph.facebook.com/APP_ID/accounts/test-users?installed=true&name=Fred&locale=en_US&permissions=read_stream&method=post&access_token=YOUR_ACCESS_TOKEN
which result in
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist: APP_ID",
"type": "OAuthException",
"code": 803
}
}
Replacing APP_ID with the proper app id, also from https://developers.facebook.com/apps resulted in the correct response.
I used the following method and it works:
https://graph.facebook.com/YOUR_APPID/accounts/test-users?access_token=YOUR_ACCESS_TOKEN&installed=true&locale=en_GB&permissions=read_stream,read_friendlists,publish_stream
the APP_ACCESS_TOKEN :
Creating an APP_ACCESS_TOKEN is really easy. You can use your App ID/API Key and App secret
YOUR_ACCESS_TOKEN = YOUR_APP_ID|YOUR_APP_SECRET
Example: 1234587968 | bghyuifjk3438483249235903502035023504305