REST API Getting 401 UnAuthorized - here-api

I am using .NET Core Web API to make call and getting back
401, unauthorized ? I am using a REST API key.
var ApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
var _Http = new HttpClient();
var response = await _Http.GetAsync($"https://geocode.search.hereapi.com/v1/geocode?q={address},{city},{state},{postalCode},{country}&apikey={ApiKey}");
What am I missing ?
I am getting the key from the following section

UPDATE: this problem has vanished today. It appears to have been a bug on the Here side.
Yesterday: My JS API code, which has been working fine, is throwing 401s today as well, with no changes. I could kill the project and create a new one with a new API key, but I'm not sure that would fix it. I did find that it was "disabled" (due to a billing issue, I think), and I "enabled" it and it still throws 404s.

Did you confirm your email address (by clicking the link in the email they send)?
If you have not confirmed your email address, then the API Key is only valid for 30 minutes.

Related

Missing initial state in WebAuthenticator login attempt

working on a .NET MAUI app and am trying to implement Firebase Authentication with the help of WebAuthenticator in MAUI. I get to the login form in a browser, but after logging in get the error
Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared.
This is the code that calls the authenticator
await client.SignInWithRedirectAsync(FirebaseProviderType.Google, async uri =>
{
var options = new WebAuthenticatorOptions
{
Url = new Uri(uri),
CallbackUrl = new Uri("com.companyname.myappname://callback/"),
PrefersEphemeralWebBrowserSession= true
};
var res = await WebAuthenticator.Default.AuthenticateAsync(options);
});
I think the problem could be the callback URL, but I'm not sure how to write it differently since I'm not using a backend API. Does anyone have any suggestions?
Thanks!
P.S. This happens with bost Firebase Google auth and Facebook login
You can try to clear the chrome browser data and reload the page to see if it works. This is a known problem of firebase. You can continue to follow up this github iissue: Unableto process request due to missing initial state.

i have a error 401 with microsoft emotion api in java

im using the example code to call the emotions api but i have an error 401 and i cannot identify the error
the result: { "error": { "code": "Unauthorized", "message": "Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key." } }
HttpClient cliente = HttpClients.createDefault();
String key ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
try{
URIBuilder builder= new URIBuilder("https://api.projectoxford.ai/emotion/v1.0/recognize");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-type","application/json");
request.setHeader("Opc-Apim-Subscription-Key",key);
StringEntity reqEntity = new StringEntity("\"url\": \"http://am-elsalv-cdn.agilecontents.com/resources/jpg/5/3/1458595472835.jpg\"");
request.setEntity(reqEntity);
HttpResponse response = cliente.execute(request);
HttpEntity entity = response.getEntity();
if(entity!=null){
System.out.println(EntityUtils.toString(entity));
}
}catch(Exception e){
System.out.println(e.getMessage());
}
The 401 error is typically shown when you’re using an invalid subscription key to call our APIs. This could happen for a number of reasons:
Incorrect key as result of a copy/Paste error when pulling the key from http://www.microsoft.com/cognitive-services/en-us/subscriptions. Additionally, make sure there are no leading or trailing spaces in your key (it doesn’t look like it from your code, but calling out for completeness).
If your key was working before and now is no longer working, you could be out of your monthly quota (number of calls) or trying to make calls too quickly for the TPS (transactions per second) supported for your key. You can check the status of your key by going to the subscriptions page, finding the emotion subscription, and clicking “Show quota”.
There is a service interruption currently on-going. If you think this is the case, please let us know through tickets#cognitive.uservoice.com.
If you’ve tried all of these things and are still experiencing issues, try to make an API call using your subscription key through our testing console. If this still fails, regenerate your key through the subscriptions page by finding the Emotion API, identify the key column, and clicking “Regenerate” under the key that is not working. Note that you’ll have to update all references to your old key as this will completely invalidate it in favor of the newly generated key.

The Access Token is Valid but We get OAuthException: An active access token error

We've been working on an application for about 2 months, and everything was going perfectly.
we were using PHP SDK and offline mode in permissions for login
But since some days ago after recent changes in Facebook api and removing offline mode we started facing the problem of "Uncaught OAuthException: An active access token must be used to query information about the current user."
The main problem is that it does happen after a while working in our app (about 10 mins) but at the same time when we check the validity of the token via this link
we see that the token is still valid on the other hand the cookie does still exist and it doesn't expire but we get this error :
"Uncaught OAuthException: An active access token must be used to query information about the current user"
I've already visited this link
and I downloaded the latest version but it didn't help could anyone help us please where might be making mistake?
Thanks for responses, I think same as yacon
it seems there's a bug when accessing facebook->api(/me) at the moment we are handling
some parts of the app with javascript which is a real headache to use javascript sdk
and PhP sdk alongside with each other
You can solve this simply store accesstoken to session variable after getLoginUrl
$facebook->getLoginUrl(...)
then whenever you initialize facebook
$facebook = new Facebook(array(
'appId' => Yii::app()->params['facebook_appId'],
'secret' => Yii::app()->params['facebook_appSecret'],
));
get the accesstoken from session and set it using setAccessToken
$facebook->setAccessToken(Yii::app()->session['access_token']);
I handle this situation in this way
1.i get the access token for 1 hour validity
2.extend the token to 60 days validity
3.save that token to session and use it for all project queries.
try{
$facebook_uid = $facebook->getUser();
$facebook->setExtendedAccessToken();
$accessToken = $facebook->getAccessToken();
$fbuser = $facebook->api('/me');
$session['api_me'] = $fbuser;
$session['tokenValue'] = $accessToken;
}catch (Exception $e) {
facebook_uid =null;
}
I think there is a bug in the api. When I use $facebook->api('/'.$facebook_uid) instead of ->api('/me') it works.

twitterizer API Value cannot be null. Parameter name: String ASP.NET

I am using Twitterizer API for accessing twitter related functionality. I have one demo application that works fine with my consumerkey and consumersecret i run this application locally. but when i integrate the same settings in my live application i got this error
Value cannot be null.Parameter name: String
Can anyone tell me why?
Thanks
Please check you keys. Also check your server time. Sometimes timestamp that we generate give some issues.
Without a stacktrace or more details, there is absolutely no way I could give you an absolutely accurate answer.
My best guess is that your request is failing, possibly because of DNS, lack of .NET permissions, or misconfigured proxy settings on the server and you're not checking if the ResponseObject is null before trying to use it.
To check for failed requests at runtime (so you can display a nice error without an ugly try/catch), check the Result property of the TwitterResponse<T> you got back from the library.
For example,
OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = "XXX";
tokens.AccessTokenSecret = "XXX";
tokens.ConsumerKey = "XXX";
tokens.ConsumerSecret = "XXX";
TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(tokens, "Hello, #Twitterizer");
if (tweetResponse.Result == RequestResult.Success)
{
// Tweet posted successfully!
}
else
{
// Something bad happened
}
That code is lifted directly from my homepage.

fql.query method returns empty string in asp.net

I have developed a web application 3 months ago to show facebook users by searching username. To access facebook, I have downloaded facebook dll and got application key, and secret key from facebook.
My web application was working fine and displaying records from facebook. yesterday onwards, my application is not working fine. I could not get response when I search by name.
I have tested the fql in the facebook testAPI tool online. That time I can get response. but the same fql I used in my appliation but it could not get response from facebook when I search by name. If I search by uid i can get response from facebook.
here is my code-
facebook.Components.FacebookService fb = new FacebookService();
fb.ApplicationKey = "bfeefa69afdfe81975f0d6136ace3009";
fb.Secret = "9b672d682e1d8befd06382953fc2615b";
fb.IsDesktopApplication = false;
//the below fql gives response as xml.
//select name, profile_url from user where uid = '1730923544' -I can get response for this fql.
//the below fql does not give response as xml. But it gives empty string.
//the below fql does gives us response as xml when i try in facebook testAPI.
//select name, profile_url from user where name = 'Suresh Rajan' -I couldn't get response for this fql.
string s = fb.fql.query("select name, pic_square, profile_url from user where name = 'Suresh Rajan'");
if (String.IsNullOrEmpty(str1))
Response.Write("Empty Response");
else
Response.Write(str1 + " <br />");
how to search by name in facebook fql.
thanks
r.e
Yesterday Facebook was having issues with their API that may have prevented some queries from working. Try it again today and it might work.
Here is facebook's api status page where they report any ongoing issues with the API:
http://developers.facebook.com/live_status.php
If it's still not working for you then it's likely the fix that they deployed for yesterday's issue had a bug in it. Here is a similar bug that occured a while ago that sounds just like this one: http://bugs.developers.facebook.com/show_bug.cgi?id=1359. You should open a new bug on the facebook bug tracker if that's the case since that one is old and has already been closed.

Resources