Hello I need to know how to call google maps API for work form inside a an ASP.NET C# code
namely the Geocoding API
I tried using this
string query = "30.0013759" + "," + "31.236013";
string address = "";
XmlDocument geocoderXmlDoc = new XmlDocument();
geocoderXmlDoc.Load("http://maps.google.com/maps/api/geocode/xml?client=gme-myclientid&latlng=" + query + "&sensor=false");
but it responded with 403 forbidden to me
can anybody help?
Read this documentation regarding 403 error for Google Maps Geocode. It says:
Why am I receiving a HTTP 403 Forbidden response to my Maps API web service requests?
An HTTP 403 response indicates a permission issue, likely because the signature could not be verified for this request. This could be because:
a. A signature has been specified but is incorrect for this request.
b. The request specifies a Google Maps API for Work client id but does not specify a signature, and the web service being called requires that all requests made using a client id include a valid signature.
c. A signature has been specified but the associated Google Maps API for Work client ID has not been specified.
Related
This C# code, with a proper access token (for scope drive.readonly) in the Authorization header, will work fine and return the file metadata in json format
_httpClient.GetAsync($"https://content.googleapis.com/drive/v3/files/{someDriveFileId}")
However this code (still with the same access token) will return a 403 :
_httpClient.GetAsync($"https://content.googleapis.com/drive/v3/files/{someDriveFileId}?alt=media")
And the following response html (exactly as returned) :
<html><title>Error 403 (Forbidden)!!1</title><a
href=//www.google.com/><span id=logo
aria-label=Google></span></a><p><b>403 Forbidden</b><p>Your client
does not have permission.\n
I've been using this code in production for years and it worked fine, so i suppose it's related to the recent changes at Google regarding the OAuth screens ?
I'm not sure what i should change here, or what i'm doing (now) wrong. Also the message seems a little sketchy for something made at Google, makes me think there is maybe an issue on their side ?
UPDATE:
Thanks to #Iamblichus for fixing the layout of my original answer. I'm newer to stackoverflow posting.
Even though the change in the original answer appears to be at the root of the problem, I found it difficult to use the troubleshooting steps to come to a working solution. I also was already passing the Authorization Bearer token solution, and that was not fixing my problem. After some trial and error the change I had to make was:
Broken GET URL:
https://content.googleapis.com/drive/v2/files/MY_FILE_ID?key=MY_KEY&alt=media&source=downloadUrl
Working GET URL:
https://www.googleapis.com/drive/v2/files/MY_FILE_ID?alt=media&source=downloadUrl
NOTE:
I am using v2 of the API, so you would need to update to url to v3 if using that.
In the file object I get from the google filepicker v2 API, I don't get back a single URL that supports the change made in authentication. I had to concat the file.selfLink string to make the new URL work
var url = file.selfLink + "?alt=media&source=downloadUrl";
ORIGINAL ANSWER:
Is it possible that https://cloud.google.com/blog/products/application-development/upcoming-changes-to-the-google-drive-api-and-google-picker-api is your problem?:
download calls to files.get, revisions.get and files.export endpoints which authenticate using the access token in the query parameter will no longer be supported.
Only requests that download media content (alt=media) are affected by this change.
The access token should be provided in the HTTP header, like Authorization: Bearer oauth2-token or, if that's not possible, follow the workarounds provided in the referenced documentation:
For file downloads, redirect to the webContentLink which will instruct the browser to download the content. If the application wants to display the file to the user, they can simply redirect to the alternateLink in v2 or webViewLink in v3.
For file exports, redirect to the export link in exportLinks with the desired mime type which will instruct the browser to download the content.
Reference:
Changes in authorization to Google Drive API
Authorization via HTTP header
v2 files get documentation
v3 files get documentation
I have this proprietary code I am working on for my job.
I am writing test cases for it because the code was changed and the test cases are now broken.
It is a C# web Api MVC .Net Framework app
I have a method that I enter a string url in
Then this code executes
HttpResponseMessage response = await Client.GetAsync(url).ConfigureAwait(true);
System.Uri uri = new System.Uri(url); // convert string to Uri
var cert = System.Net.ServicePointManager.FindServicePoint(uri).Certificate;
response.EnsureSuccessStatusCode();
when it gets to response.EnsureSuccessStatusCode() , it gives a 401 unauthorized and then throws an exception not allowing my test to pass
When I try the same thing with http://www.google.com which is not an https, then
it gives a 200. So something is going on with security stuff
What are the things I need to do to get a https to give a 200? Does it need username and password credentials or something or some other token of some sort?
Also, when I test it using Rest Client DHC with the secure https link that was failing above it gives me a 200. However, I had to refresh the bearer token for it to give a 200. If I used an old token it would give a 401.
Furthermoore, when I test a different link like https://www.facebook.com (which is not the one I want to test in my application, just troubleshooting) which is secure, it works giving me a 200 both in my application above and Rest Client DHC even with an old bearer token.
If you're trying to makes CORS requests to web API, you'll need to configure It to accept cross origins requests. If you dont configure your web api to accept cross origin requests, it'll throw these type of errors when calling It. And keep in mind that for web api access, https://www.domain.so and http://www.domain.so are completely diff clients.
Look at this link:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api
I am simply trying to send an sms using the clickatel API.
I have used the helper library found here: https://github.com/clickatell/clickatell-csharp
var apiClient = new RestClient(new RESTCredentials(ApiKey));
var result = apiClient.Authenticate();
Debug.Write("_apiClient.Authenticate() = " + result.Result);
and I get the following:
"Error occured during Clickatell Authenticate. Details: The remote server returned an error: (401) Unauthorized."
I have checked the api key several times, I have even regenerated a new on on their portal.
Am I missing something?
I see you're using the old Clickatell Csharp library that was written for the old endpoint.
You will need to use the new script which can be found at https://github.com/clickatell/Clickatell-Csharp-Platform
Hopefully this will resolve the issue.
I'm creating a twitter login api for our mobile web application. I got this 404 not found error as return message in console. this is the full url for twitter callback
https://api.twitter.com/?oauth_callback=http%3A%2F%2F127.0.0.1%3A4268%2Fmobileapp%2F&oauth_consumer_key=<keyhere>&oauth_nonce=7540630&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1396766598&oauth_version=1.0&oauth_signature=9TjVwKWGyqYEGYdfl1s56k%2BCaaY%3D
is there something wrong with the return url?
thanks
No, the problem is not in the return url.
The problems are:
You're sending the URL to https://api.twitter.com/ without any further URI to indicate the service that you're requesting. Since you are passing an oauth_callback, it's likely that you wanted to access https://api.twitter.com/oauth/request_token
You can't pass an oauth_callback to oauth/request_token using a GET request: you need to use a POST request instead.
Hopefully that explains for you what's wrong with this URL.
If you are having more problems accessing the Twitter oauth API, I suggest that you read this primer from Twitter on how to use this API:
Implementing Sign in with Twitter
I'm following this Url to authenticate user to my website using twitter login. I'm able to get the access token but when im calling below code
url = "http://twitter.com/account/verify_credentials.json";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
im getting 401 unauthorized error. Can anyone guide me what can be the problem
I am not an expert on the Twitter API's but here is a post in the dev.twitter forums that seem to be very similar to what you are experiencing.
https://dev.twitter.com/discussions/1750
Your URL is wrong. It is https://api.twitter.com/1.1/account/verify_credentials.json (or https://api.twitter.com/1/account/verify_credentials.json depending of the version of the Twitter API (1 or 1.1) you use). Twitter recently removed endpoints whose domain name is not api.twitter.com and endpoints without the version of the API : https://dev.twitter.com/discussions/10803
If it is still wrong, ensure that you authorize your requests correctly : https://dev.twitter.com/docs/auth/authorizing-request
NB : Twitter will send you back JSON datas, not XML. You should write "json = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" instead of "xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);" in your code. If you want XML datas, use this URL : https://api.twitter.com/1/account/verify_credentials.xml. But this last will not work after March 2013.