We've been using the Foursquare SharpSquare api to add checkins with success. We recently noticed that we're getting a "(411) Length Required" error. We get this error most of the time now, but once in a while it will post successfully. The general consensus to fix this error seem to be to add Content-Length=0 to the header, but i'm not sure if that's possible with SharpSquare. Any ideas?
It sounds like the SharpSquare api does not properly add a Content-length header. If this is not possible from using the SharpSquare API, you may need to update the SharpSquare source so this is performed correctly, or craft your own HTTP request without using the SharpSquare API.
Related
I'm having difficulties on retrieving data from my server. I activated CORS and set up my call properly(already tested it with postman). I'm sending the post request to my server, method is being hit but when returning and trying to read the response on the client side, the SDK fails.
This is the error I'm getting on the console.
Am I missing something here? do I have to use another plugin for the htttp calls in web environment?
Error information is incomplete, in which line do you get error?
I assume your uri and some other thing are ok.
change filtereDto to:
Map<String,dynamic> filterDto={
'date':'2020-02-07....',
'countryId':'1' // string number
}
And you dont need to :
json.encode(filterDto)
in post call, only filterDto is enough
... body: filterDto ...
I have found the issue. Cors was being enabled on my server side incorrectly. Order activating Cors is critical for configurations to be applied properly in a .Net core app.
This is how is done. First activate Cors and then MVC.
Hope it helps anyone who is struggling with the same thing.
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 created GET,POST,PUT and DELETE methods in my sample Web api.
Using fiddler, I am adding resources using POST method and getting status 201 created with location.
But when I am calling through its URI, I am getting not found exception.
You probably call the POST-method with a GET http method. Then you get a 4xx error.
I suggest using a "Advanced REST client" (search google- chrome plugin) to post your data. Then you can use the right HTTP methods in your web api.
I'm trying to get to grips with OneDrive, using this tutorial:
https://msdn.microsoft.com/en-us/library/hh826529.aspx
When I run in code, it gets as far as the makeAccessTokenRequest function, sending the following requestURL:
"https: //login.live.com/oauth20_token.srf?client_id=[myclientID] &client_secret=[myclientsecret]&redirect_uri=https:// login.live.com/oauth20_desktop.srf&grant_type=authorization_code&code=[authcode]"
(please ignore the spaces after "https:", I had to add them here to allow the question)
[myclientid], [myclientsecret], and [authcode] all appear to be populated correctly. It seems to get a response, as it runs the function "accessToken_DownloadStringCompleted", but throws a "TargetInvocationException" error, The inner message of the error is ""The remote server returned an error: (400) Bad Request.".
Could anyone throw any light on this? I'm completely new to this, so apologies if my question makes no sense, or is irritatingly vague..
Requests to the oauth20_token.srf end point need to be a POST with the parameters in the body of the post, instead of the query string. Since you didn't mention what code you're using to build the HTTP request it's hard to provide an example, but take a look at RedeemAuthorizationCodeAsync in my sample OAuth 2 project for an idea.
The outgoing request should look like this:
POST https://login.live.com/oauth20_token.srf
Content-Type: application/x-www-form-urlencoded
client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}&code={code}&grant_type=authorization_code
You may also find this tutorial easier to follow than the one you linked with: https://dev.onedrive.com/auth/msa_oauth.htm.
If you are doing something with OneDrive (you tagged the post OneDrive) then you may want to consider using the OneDrive SDK instead. It includes authentication for several types of .NET projects so you don't need to figure out how to do auth yourself.
Very new to this. I am using a wsdl. Generating the web reference and .net builds the classes in references.cs. Now is there any way I can get the soap request going out though any c# methods in my code?
Getting at System.Xml.Serialization.XmlSerializer.Serialize error in prod but absolutely working fine in UAT. No body has no clue on why? Can someone pls provide insights on getting the soap request going out ?
You can use tool fiddler to track the request and responce