I am attempting to pull my trade history from Binance (using signed endpoint security) into google sheets so that I can keep records of all my trades using google scripts. I am stuck where I can't pull the data using the api keys. The below snippit is as far as I could get from my understaning of the Binance API and UrlFetchApp API.
var data = UrlFetchApp.fetch("https://api.binance.com/api/v3/myTrades", {headers : apiKey})
I also have found this post.
Binance API Website
You can't add the header in the url bar.
EDIT I see you are using UrlFetchApp. In that case, the correct syntax is
var headers = {'X-MBX-APIKEY': apiKey}
UrlFetchApp.fetch("https://api.binance.com/api/v3/myTrades", {'headers': headers})
Related
I've been using a public google spreadsheet as a JSON endpoint for several of my web projects for some time now. I liked this approach because I could retrieve data from a public spreadsheet without needing any kind of authentication or tokens to get the data, all I needed to do was publish the spreadsheet and then fetch from a simple URL:
fetch(`https://spreadsheets.google.com/feeds/${mode}/${id}/${sheetNum}/public/values?alt=json`).then((res)=>console.log(res));
Google is deprecating sheets v3, and I'm confused about how to migrate to v4. From this answer I gather that I need to provide an access token which is created via the google cloud console. But do I need to create some kind of special "app" or "workplace" or will any old API token do? I tried the following:
Create a GCP project
Enable Google Sheets API
Hit Create Credentials
fetch data using the following URL scheme:
fetch(https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/RANGE?key=API_KEY)
But this is giving me a 403 response.
You are using the JSON Alt Type variant of the Google Data protocol. This protocol is dated and appears to no longer work reliably. The GData API Directory tells:
Google Spreadsheets Data API: GData version is still live. Replaced by the Google Sheets API v4.
Google Sheets API v4 is a modern RESTful interface that is typically used with a client library to handle authentication and batch processing of data requests. If you do not want to do a full-blown client implementation, David Kutcher offers the following v4 analog for the GData JSON Alt Type, using jQuery:
GData (old API, not recommended):
var url = 'https://spreadsheets.google.com/feeds/list/' +
spreadsheet_id + '/' + tab_ordinal + '/public/values?alt=json';
($.getJSON(url, 'callback=?')).success(function(data) {
// ...
};
V4 (new API, recommended):
var url = 'https://sheets.googleapis.com/v4/spreadsheets/' +
spreadsheet_id + '/values/' + tab_name +
'?alt=json&key=' + api_key;
($.getJSON(url, 'callback=?')).success(function(data) {
// ...
};
...where:
spreadsheet_id is the long string of letters and numbers in the address of the spreadsheet — it is the bit between /d/ and /edit
tab_ordinal is number of the sheet — the first sheet that appears in the tab bar is sheet number 1, the second one is 2, and so on
tab_name is the name of the sheet, i.e., the name you see in the tab bar at the bottom of the window when you have the spreadsheet open for editing
api_key is the API key you get from from Google Cloud Platform console
Note that the JSON output format differs between the two versions.
The old GData JSON Alt Type variant API requires that the spreadsheet is made public through File > Publish to the web. V4 requires that the file is shared with "anyone with the link can view" through File > Share.
FINDINGS
The URL scheme produces the error 403 because mostly likely the spreadsheet file isn't shared publicly like this:
I can also replicate the 403 error when my test sheet isn't shared publicly using the same URL scheme:
RECOMMENDATION:
You can double check the spreadsheet file you're accessing and check it's sharing permission, making sure it's set to Anyone with the link:
TEST RESULT
Publicly shared test sheet
After setting up the spreadsheet file's sharing permission to Anyone with the link using the same v4 URL scheme:
I have been trying to fetch from the Open Weather API but an error message kept appearing on the console. It returned 'unauthorized' and 'message: keys does not exist' after persistent tries.
fetch("https://community-open-weather-map.p.rapidapi.com/weather?callback=test&id=2172797&units=%22metric%22%20or%20%22imperial%22&mode=xml%2C%20html&q=London%2Cuk", {
"method": "GET",
"headers": {
"x-rapidapi-host": "community-open-weather-map.p.rapidapi.com",
"x-rapidapi-key": "15XXXXXXXXXXXXXXXXXX"
}
I'm not sure why you are using rapidapi here, but if you simply want to fetch data from openweathermap, you need to do the following:
Sign up to get unique API key (free plan exist)
Provide the key as part of your URL, like:
http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY},
When APIKEY is your unique API key
Also make sure you do not use the API key from the demos provided by open weather map, as it will result with errors when used from domain other than openweathermap, And tha if you're using a free plan, you're limited to maxium of 60 request per minute.
Check out the docs about how to get started with openweathermap.
As per the fetch function response, it looks like that the API key you are using is invalid or expired.
I'm able to replicate the issue in my setup.
I found one working API key on rapidapi site and after using the key the issue is resolved.
The working Key Api key is : 490f920aa3msh1db5e8f1c73a050p1cbd06jsn83595422113e
You can also use the above key as a quick workaround.
I have a WordPress site and I am using a NPM package to call the Google Geocoding API from google and get the latitude and longitude from an address, it includes the API key and the address to look for. I had to un restrict my API key on my google console because I was getting an error when I was trying to do the call.
The package is here: https://www.npmjs.com/package/#google/maps
What I am trying to achieve is to restrict my API key to be used only on the site. Right now it is only restricted with Geocoding API, Javascript Maps API and Places API filters so it won't be used with any other kind of library.
I am only using the geocoding functionality on the site and nothing else so it doesn't make sense to have a Map, but I have the places and maps libraries active because on the WordPress admin I use them.
I tried the HTTP referrer restriction with the website domain name and IP address restriction with the server IP where the site is being hosted but none of these worked.
I have a googleClient object which handles the Geocoding API
let requested_address
googleClient.geocode({address: requested_address})
.asPromise()
.then((response) => {
// Call to another function passing the location object from response
showLocations(response.json.results[0].geometry.location)
})
.catch((err) => {
// print error message in screen
$('.results-message').show().html(err.json.error_message)
});
I get an error with this message:
API keys with referer restrictions cannot be used with this API.
I am trying to get a way to use this same package with the API Key restrictions so it is not used on other sites/apps or other way to get the location latitude and longitude, even if you just put a zip code or a non complete address as Google Geocoding does.
I have been struggling for a while just one small authorization problem. so I am able to get an access_token with auth 2.0. and I tried to pull data from the private spreadsheet. There are several challenge.
When I read the google spreadsheet API. For private, I might need an OAuth 2.0 authorization or google API Key.
So I used OAuth, now have an access_token. I put https://sheets.googleapis.com/v4/spreadsheets/{{spreadsheet_id}}/values/{{spreadsheet_name}}!A1:D3?access_token=" +gDriveKey.clientID
Consequence => the error msg (I need to put API Key).
So I create an API Key on API Manager -> credential
https://sheets.googleapis.com/v4/spreadsheets/{{spreadsheet_id}}/values/{{spreadsheet_name}}!A1:D3?access_token=" +gDriveKey.clientID + "&key="+gDriveKey.apiKey
Consequence => the error msg (The caller does not have permission) status : "403".
and I believe I give the right permission scope on the OAUth
My scope was: ["https://www.googleapis.com/auth/spreadsheets","https://www.googleapis.com/auth/drive"]
Can you guys please tell me what was the problem??
Thank you.
I generated Browser API Key in Google Console and set referrers:
Then I go to http://afriflirt.com, open JS console in browser and run this code ("Google Maps Geocoding API" enabled for this api key in settings):
var apiKey = 'AIzaSyAGpR-mG46fDbmWjJwkZZHft_xvZ_dM3cA';
$.getJSON(
'https://maps.googleapis.com/maps/api/geocode/json?address=12345&key=' + apiKey,
function(resp) {alert(JSON.stringify(resp));}
);
in response I see this message:
This IP, site or mobile application is not authorized to use this API
key. Request received from IP address 113.180.75.109, with referer:
http://afriflirt.com/
If I remove referrers - API key start working, but this is not safe.
So it's a problem only when I set referrers. Tried different formats of referrers patterns, but nothing worked. Also tried to wait some time (as I saw "it may take up to 5 minutes for settings to take effect"), but it doesn't help too.
Please let me know if you have any ideas how to fix this.
According to the documentation, you need a server key for the geocoding web service.
Create a server key, enable it for IP address: 113.180.75.109, that should work in your example (but it isn't recommended to use a server key from javascript like that, use a browser key and the Google Maps Javascript API v3 Geocoding Service).