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.
Related
I struggled with this annoying bug for a very long time. The issue was when trying to get the users UID via the two-legged API users/me it would result in an response from the API: Duplicate timestamp/nonce combination, possible replay attack. Request rejected. My work around for a while was basically brute forcing this API endpoint until it responded. This worked sometimes but is obviously not practical.
After going through post after post of people also having this problem I looked at the answers from Schoology support and they all said visit the docs, which I have looked over multiple times before. however this time I scrolled down and found a "short-cut" as they called it to get the UID:
So instead of trying to use the users/me endpoint you simply use the endpoint: /app-user-info which returns a JSON with timestamp and UID!
After you get the UID you can freely access the users/me endpoint by replacing me with the UID like so: users/{UID}
URL:
https://api.schoology.com/v1/app-user-info
two-legged Authorization header:
OAuth realm="Schoology API",
oauth_consumer_key="{CONSUMER_KEY}",
oauth_signature_method="PLAINTEXT",
oauth_timestamp="{TIMESTAMP}",
oauth_token="",
oauth_nonce="{RANDOM_CHARS}",
oauth_version="1.0",
oauth_signature="{CONSUMER_SECRET}%26"
I can't for the life of me append to my google sheet via http request. More specifically I can't seem to get the Oauth formatting right. I don't want/need a uri or prompt for permission as its just me managing my own spreadsheet. First, I was trying with just my api key, but then found out that if you're editing data you need to obtain an access token. That's when I started trying to obtain the token through oauth2 following the TERRIBLE google api documentation. That's where I hit a wall and have just about given up. It's such a simple concept, I just want to add data to my spreadsheet on drive from an online script (housed on scriptr.io), but Google yet again makes things so unneccessarily complicated and don't help matters with their convoluted, misleading, and scattered documentation. Can someone please help me in accomplishing this? Here's where I'm at or what progress I've made thus far.
I've figured out how to correctly format the call to add a row of data to the spreadsheet.
POST https://sheets.googleapis.com/v4/spreadsheets/-/values/Raw%20Data!A1:D1:append?valueInputOption=USER_ENTERED
//Header
Authorization: Bearer {oauth_token}
//Payload
{"range": "Raw Data!A1:D1","majorDimension": "ROWS","values": [["Test", "$15", "2", "3/15/2016"]]}
I know the above works because I've successfully added the data using the OAuth 2.0 Playground. However, when trying it outside of the playground (on a rest client) I keep getting errors trying to obtain the token.
POST https://www.googleapis.com/oauth2/v4/token
scope=https://www.googleapis.com/auth/spreadsheets
client_id=------&
client_secret=-----&
refresh_token=-----&
grant_type=refresh_token&
access_type=offline
I use the client id & client secret from my api console and I use the refresh token I got by authorizing the spreadsheet api in the oauth playground, but the above POST request leads to the following error
Error 400
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: "
}
Can someone please help me figure out how to correctly do this?
The question is simple.
I got the access_token by Oauth 2. and I want to access spreadsheet on google to read.
But When I read api from https://developers.google.com/sheets/ .
I don't get where to put access_token or do i even need it.
I tried to put my access-token on url and failed..
for instance: var sample_url = "https://spreadsheets.google.com/pub?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc&hl=en&output=html?accesstoken=" + accesstoken;
I got the response back. it says "{"data":{"error":{"code":403,"message":"The request cannot be identified with a client project. Please pass a valid API key with the request.","status":"PERMISSION_DENIED"}},"status":403,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"https://sheets.googleapis.com/v4/spreadsheets/1ZduILENRVcnzXTynV00j9puWJEvGgz-EcxOgoPRpOGI/values/A1:D3?ya29.Ci87A42OTqtIqXylTU7QxZALwJjRuf_oXf2FJ-MTY7QvXgWzPhZEKhi4Yhn7HVVV7g","headers":{"Accept":"application/json, text/plain, /"}},"statusText":""}"
I know I have to attach the access-token somehow, but i don't know how.
Do you guy have any idea for the spreadsheet api?
Thank you for reading this
I am not familiar with the ionic-framework, but to use the access token, you should either add that into the HTTP headers (e.g. Authorization: Bearer ya29.xxxxxxxxxxxxxxxxxx) or include that in your query string,
Ref: https://developers.google.com/identity/protocols/OAuth2InstalledApp#callinganapi
There is a mistake in your sample_url, it should be &access_token= instead of ?accesstoken=
It should be,
var sample_url = "https://spreadsheets.google.com/pub"
+ "?key=0Ago31FFWG3xZrdHF2bWNjcTJFLXJ6UUHYT3dEakdEaXc"
+ "&hl=en&output=html&access_token=" + accesstoken;
I had a same requirement of accessing the google spreadsheet from the ionic cellphone, and we have used tabletop.js. Using this we were able to read the spreadsheet completely.
Try this if it helps you anyway.
https://github.com/jsoma/tabletop
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).
I'm trying to use Google Calendar API via JavaScript and keep getting the 401 error response while using the following code:
$.ajax({
dataType: "json",
url: "https://www.googleapis.com/calendar/v3/users/me/calendarList/<calendarID>?key=<my api key>",
success: function(result){
$('#result').html(result);
}
});
Is there something wrong in my usage of the API and how should I use the oAuth? I already have a clientID and secretID from the Google console but don't know how to use those.
Thanks.
Here's the answer after quite a bit of research, I just found and used this guide for using google calendar api
http://googleappsdeveloper.blogspot.com/2011/12/using-new-js-library-to-unlock-power-of.html
Then I still was confused since the api key wasn't working every I tried regenerating it a couple of times. Then I had to use the browser key without any referrers just as mentioned here: Getting Error 403: Access Not Configured. Please use Google Developers Console to activate the API for your project
and finally I got everything working.
Here's also a main article for understanding the OAuth2
https://developers.google.com/accounts/docs/OAuth2
In order to use Google Calendar API, you not only need the client ID and client secret but in most cases (other than accessing public calendars) you also need to have your user authenticated. One way to achieve that is using Oauth2.
I recommend using the client library that you can download here: https://developers.google.com/google-apps/calendar/downloads
Also there is an example on how to use the library here: https://developers.google.com/api-client-library/javascript/samples/samples