Google Drive file download API failure - google-api

I have an app which prints files from a Google drive account. It uses the API https://drive.google.com/uc?id=&export=download to download the content and sends for printing. Instead of downloading the correct content some junk characters are being downloaded from the last two days. I tried this API in postman and got the same result.
HttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("drive.google.com/…)
.get().addHeader("Authorization", "Bearer xxxx"")
.addHeader("cache-control", "no-cache")
.addHeader("Postman-Token", "02efaa73-543e-4b02-bbd4-570cfbd3f9f4")
.build();
Response response = client.newCall(request).execute();

Related

MAUI / Xamarin HttpClient on Android not sending Bearer Authorization Header on GET to API

Struggling with MAUI to send a GET call from Android device to an API that requires Bearer auth. Setting the Authorization header in the HttpClient like so:
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);
However at the API endpoint, the Authorization header is not being received at all.
We have also tried sending an HttpRequestMessage with the Authorization header set explicitly, but still no dice.
It turned out the API we were sending to was running on both HTTP and HTTPS URLs.
In our android client config, we were sending to the HTTP URL.
Then we noticed that our API was set to redirect HTTP->HTTPS : app.UseHttpsRedirection();
So it turns out that Auth headers are stripped on redirect!
Authorization header is lost on redirect
When we changed our Android config to call the HTTPS URL directly, the Auth header started being received correctly.

Microsoft Teams API Response can't display Chinese/Japanese

I'm working with Microsoft Teams API with HTTP requests.
When I use Graph Explorer to retrieve my channel messages, it works fine.
However, when I try to use another platform to send the HTTP request, it shows something like \u3042\u308a\u304c\u3068\u3046 instead of Chinese or Japanese.
I tried to use UTF8, UTF16, ASCII to encode the response, however, the problem still remains.
UPDATED
My Http request works fine in graph explorer and postman, see below images.
However, when I tried to get the request with REQBIN which is an online request system, the result is not encoded, see below.
When I use unity to run this request with UnityWebRequest, the response is also not encoded. My C# code is as below,
UnityWebRequest www = UnityWebRequest.Get("api_link");
www.SetRequestHeader("Authorization", "Bearer " + getUserToken.userToken);
www.SetRequestHeader("Content-Type", "application/json");
yield return www.SendWebRequest();

Can't restrict API key access when making Ajax requests to Google TIme Zone API

I'm making requests to Google Time Zone API using Ajax and by following this tutorial:
var apicall = 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY'
var xhr = new XMLHttpRequest() // create new XMLHttpRequest2 object
xhr.open('GET', apicall) // open GET request
xhr.onload = function(){
if (xhr.status === 200){ // if Ajax request successful
var output = JSON.parse(xhr.responseText) // convert returned JSON string to JSON object
console.log(output.status) // log API return status for debugging purposes
if (output.status == 'OK'){ // if API reports everything was returned successfully
// do something
}
}
else{
alert('Request failed. Returned status of ' + xhr.status)
}
}
xhr.send() // send request
I've replaced the key parameter with my generated API Key in Google Console, and the request works. The problem is I can't seem to restrict the API key access by either Referrer or Server IP in Google Console- specifying the domain of my server or IP doesn't work. My guess is Ajax doesn't send referrer or server IP info along with the request for Google to determine if it's a valid request? At the moment I'm stuck with using no API key restrictions, though this is not a good idea of course.
Anyone have any experience restricting Google API key access when making calls to Google APIs via AJax?
just remind, just do not embed API keys directly in code
google api

Braintree ios + java transaction API returns 403

Just started the project. The client side app is the Braintree demo app. I modified it to point to my server running on localhost
Here is what I'm doing.
ios app makes an request to server to get a token
server uses method below to get a token from Braintree and sends back to server
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX,
merchantAccountId,
".........",
"............."
);
String token = gateway.clientToken().generate(); // Braintree did return a token
ios demo app creates a nonce with the drop-in view
ios demo app sends the nonce to the server
// nonce sends to server 71a89c9d-6ca7-4804-a895-b0e7564425c6
server calls Braintree API with code below
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal(19.0f))
.merchantAccountId(merchantAccountId)
.paymentMethodNonce(nonce)
.options()
.submitForSettlement(true)
.done()
.channel("MyShoppingCartProvider");
Result<Transaction> result = gateway.transaction().sale(request);
return result;
The last step got 403 com.braintreegateway.exceptions.AuthorizationException exception from Braintree. The xml from the error stream is Unauthorized. The input stream from Braintree says "Server returned HTTP response code: 403 for URL: https://api.sandbox.braintreegateway.com:443/merchants/vb38crtnzn77b9ys/transactions"
Thanks for the help
It turns out that there are two IDs. One is merchantId and the other merchantAccountId. The server sends back the merchantId back to client. And later for charging, use merchantAccountId.

JSON interaction after OAuth2/OmniAuth authentication

Context: I'm trying to interact with Twitter via JSON and no libraries as i'm practicing to interact with a newly released receipt printer(themprinter.com) which has no helper libraries. I need to OAuth with the printer then make the appropriate calls to register my device, print, verify online/offline status etc.
I've successfully authenticated with Twitter via OmniAuth's Twitter Gem. I can pull all the data from the Authentication Hash here - https://github.com/arunagw/omniauth-twitter
...now what? I want to be able to make a JSON call with my OAuth credentials to Twitter and pull my timeline or any other such data. Can anyone provide any sample code that will allow me a starting point to tinker with and work off of?
Twitter provides REST API. Here's how you might create a GET REST request
request = Net::HTTP::Get.new(url, initheader = header)
http_request = Net::HTTP.new(host, port)
response = http_request.start {|http| http.request(request)}
here's an example of the request URL:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2

Resources