Unknown authorization header when using java gdata sdk - google-docs-api

Lately, we are hitting about 30% failed API calls in our regression tests, caused by "Unknown authorization header" exception.
We are getting the following exception from gdata java sdk:
Caused By AuthenticationException:
com.google.gdata.util.AuthenticationException: Unknown authorization header
<HTML>
<HEAD>
<TITLE>Unknown authorization header</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unknown authorization header</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:998)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
at com.google.gdata.client.Service.getFeed(Service.java:1017)
We are running our regression tests using gdata api, using over 20 JVM for each test case.
This error is new. It emerged without changing our implementation, nor a significant change in load.
However, the error rate changes accordingly as we change the number concurrent JVMs, dropping to about 10% error rate as we reduce the number of JVMs to a few ones.
We would appreciate any help regarding the cause of the error and possible fixes.
Thanks
Assaf

private DocsService getDocsService(boolean withHeader) {
DocsService docsService = new DocsService(APP_NAME);
try {
docsService.setOAuthCredentials(getAuthParameters(),
new OAuthHmacSha1Signer());
if (withHeader) {
docsService.getRequestFactory().setHeader("If-Match", "*");
}
return docsService;
} catch (OAuthException oAuthException) {
throw new TestFlowException(
"Failed to set Google Drive Oauth Credentials",
oAuthException);
}
}
private GoogleOAuthParameters getAuthParameters() {
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(GOOGLE_DRIVE_KEY.getKey());
oauthParameters.setOAuthConsumerSecret(GOOGLE_DRIVE_KEY.getSecret());
oauthParameters.setOAuthToken(ACCESS_CREDENTIALS.getKey());
oauthParameters.setOAuthTokenSecret(ACCESS_CREDENTIALS.getPassword());
return oauthParameters;
}

Related

I cannot access the my library when running my VodaPay Mini-Program web-view app from a browser

I am busy developing a mini-program using VodaPay mini-programs and rendering my web-page in an H5 web-view.
I have imported the CDN and it works correctly in the Simulator and while running on device on the VodaPay super-app. But when running on device I get the following error:
my is not defined
How do I prevent this from occurring? And why does this issue occur?
<script type="text/javascript" src="https://appx/web-view.min.js"></script>
<script>
// Sends message to VodaPay Mini-Program.
my.postMessage({name:"test web-view"});
// Did receive message from VodaPay Mini-Program.
my.onMessage = function(e) {
console.log(e); // {'sendToWebView': '1'}
}
</script>
The Web-View cdn will only run when your mini-app is running on device or in the Simulator. Therefore it is necessary to first check if the my. library is available in order to establish that it's running in a Mini-Program context.
<!-- MINI: Used to communicate with mini app. Have to include the script body here otherwise we get my. not recognized errors <START>-->
<script src="https://appx/web-view.min.js"></script>
<script id="messageSend">
function sendMessage(data) {
//If not in mini app webview then my. throws errors
try {
my.postMessage(data);
} catch(error) {
//Prevent my. from throwing error in browser
}
}
</script>
<script id="messageReceive">
try {
//Store message in session storage, and then change messageReceiveListener innerText to trigger a mutation event to notify that a message has arrived.
my.onMessage = function (e) {
sessionStorage.setItem('message',JSON.stringify(e));
document.getElementById('messageReceiveListener').innerText = e;
}
sessionStorage.setItem('inMiniProgram',true);
} catch(error){ //Prevent my. from throwing error in browser
sessionStorage.setItem('inMiniProgram',false);
}
</script>
<input id="messageReceiveListener" hidden></input>
<!-- MINI:<END> -->
The difficulty with wrapping all calls in try-catch is that you could be masking other errors too. What I'm doing instead is to check if the useragent contains "alipayclient" and render the html/js content conditionally, which also reduces the amount of html/js rendered for all other non-Vodapay users of the website.

"Invalid OAuth access token" when using valid token

When trying to use the Deezer JS SDK to access /user/me, I keep getting error code 300 (Invalid OAuth access token). My code is mostly copied from the examples so I can't figure out why this would be happening. I've tried manually specifying the token in the API call, and directly accessing the API via HTTP and haven't gotten past the Invalid Access Token error. What am I doing wrong?
index.html:
<!doctype html>
<html>
<body>
<div id="dz-root"></div>
Login
Get Login Status
Me
<script type="text/javascript" src="http://cdn-files.deezer.com/js/min/dz.js"></script>
<script src="js/index.js"></script>
</body>
</html>
index.js:
DZ.init({
appId: "253122",
channelUrl: "http://mopho.local/deezer-channel.html",
});
document.getElementById("dtest").addEventListener("click", () => {
DZ.login(function(response) {
console.log("1",response);
}, {perms: 'basic_access,email'});
});
document.getElementById("lstat").addEventListener("click", () => {
DZ.getLoginStatus(function(response) {
console.log(response);
});
});
document.getElementById("getme").addEventListener("click", () => {
DZ.api('/user/me',
function(response) {
console.log("2",response);
}
);
});
deezer-channel.html:
<script src="http://cdn-files.deezer.com/js/min/dz.js"></script>
mopho.local is configured in my hosts file + nginx to point to 127.0.0.1.
My Deezer app has the following configuration:
Application domain: mopho.local
Redirect URL after authentication: http://mopho.local
This turned out to be a permissions issue. I changed the permissions to "basic_access,email,offline_access,manage_library,manage_community,delete_library,listening_history" and it worked. I'm not sure which of the returned data points were associated with which permissions, but my guess is that some of the permissions were changed on the back end and the examples in the docs haven't caught up.

Can't get transports in SignalR

When I run $.connection.hub.start() I get these errors from "resources" (I traced it).
These are the errors i'm getting
errorOnNegotiate -> "Error during negotiation request.".
errorParsingNegotiateResponse -> "Error parsing negotiate response.".
errorSourceError -> "Error raised by EventSource".
eventSourceFailedToConnect -> "EventSource failed to connect.".
longPollFailed -> "Long polling request failed.".
noConnectionTransport -> "Connection is in an invalid state, there is
no transport active.". nojQuery -> "jQuery was not found. Please
ensure jQuery is referenced before the SignalR client JavaScript
file.". noTransportOnInit -> "No transport could be initialized
successfully. Try specifying a different transport or none at all for
auto initialization.".
Part of the error is this : "jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.""
you need to add jQuery reference this can be done like so (Please note that in this sample the signalR version is 2.0.2 you need to add the correct reference to the version you are using):
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.0.2.min.js"></script>
It looks like you've pasted the contents of the resources object within signalR._.error(). That object contains a list of possible errors, not the error your're getting. For example, here it's being used to get the error message when the negotiation response couldn't be parsed:
try {
res = connection._parseResponse(result);
} catch (error) {
onFailed(signalR._.error(resources.errorParsingNegotiateResponse, error), connection);
return;
}
To see which error you're actually getting, look at what the code is trying to utilize from this object.

Consume WCF Rest Service in ASP.net using jquery

I am trying to consume a wcf rest api in a asp.net project using jquery. for doing so i have done:
Created a WCF Rest service source code can be downloaded from here.
Created a ASP.Net project to consume that restAPI using jquery. source code here.
In ASP .Net project on the click of button I am trying to call a REST service. But every time I gets two issues:
calling var jsondata = JSON.stringify(request); in TestHTML5.js throws an error saying "Microsoft JScript runtime error: 'JSON' is undefined"
When I press ignore it continues towards WCF Rest API call but it always returns error (Not Found) function. Rest API never gets called.
Thanks for every one's help in advance.
ANSWER:
Solution and source link can be found on this link.
I have looked at the sample code you provided and the problem is that you are violating the same origin policy restriction. You cannot perform cross domain AJAX calls. In your example the service is hosted on http://localhost:35798 and the web application calling it on http://localhost:23590 which is not possible. You will have to host both the service and the calling application in the same ASP.NET project. You seem to have attempted to enable CORS on the client side using ($.support.cors = true;) but on your service doesn't support CORS.
Another issue saw with your calling page (TestHTML5.htm) is the fact that you have included jquery twice (once the minified and once the standard version) and you have included your script (TestHTML5.js) after jquery. You should fix your script references. And yet another issue is the following line <script type="text/javascript"/> which is invalid.
So start by fixing your markup (I have removed all the CSS noise you had in your markup in order to focus on the important parts):
<!DOCTYPE html>
<html dir="ltr" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>SignUp Form</title>
<script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../Scripts/TestHTML5.js"></script>
</head>
<body>
<button id="Send" onclick="testHTML5OnClick();">
Send Me ID!
</button>
</body>
</html>
and then in your TestHTML5.js you could also clean a little bit. For example your service is listening for the following url pattern json/{id} and accepting only GET verbs and you are attempting to use POST which is not possible. In addition to that you are attempting to use the JSON.stringify method which doesn't make any sense with the GET verb. You should simply send the id as part of the url portion as you defined in your service.
function testHTML5OnClick() {
var id = 5;
var url = "../RestServiceImpl.svc/json/" + id;
var type = 'GET';
callLoginService(url);
}
function callLoginService(url, type) {
$.ajax({
type: type,
url: url,
success: serviceSucceeded,
error: serviceFailed
});
}
function serviceSucceeded(result) {
alert(JSON.stringify(result));
}
function serviceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
Did u add this reference?
script type="text/javascript" src="../../json.js"></script>
I have same problem and search i get this and this result

MVC App is no longer logging in through Facebook

I have been developing an app using the Facebook add ons to enable Facebook users to log in and the app to access details such as profile pictures.
Yesterday the app was working perfectly and my development was continuing as normal.
This morning I tried to log in to check how far I'd got and was confronted with an Access Token error message.
Individual Partial Views would load up okay, but the site as a whole would not. On further investigation I found that the log in screen was assigning a new Access Token, but by the time the site tried to bring up the Master Page the token was null.
My log in is as follows :-
<html>
<head>
<title>Log On</title>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '***app no***',
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.Event.subscribe('auth.login', function () {
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<div class="fb-login-button" data-scope="email">
Login with Facebook
</div>
</body>
</html>
This is frying my head.
The error that is returned is (OAuthException) An active access token must be used to query information about the current user.
Hope this is enough information for someone to find a solution.
Many thanks
You have not set the channel url i.e you website path(that can be localhost or server domain)
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '***app no***',
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
status : true,
cookie : true,
xfbml : true,
oauth : true
});
Also you have to set your url path in developer.facebook.com from where you got your app-id.....
Okay, found some information suggesting that changes to the Facebook SDK made at the start of December will be what caused my problems. On the advice given I ran the reference updates on the Facebook references in my project. This has removed the facebookSettings line from the Web.config and the following error message now appears six times in the warnings box.
Reference to type 'Facebook.IFacebookApplication' claims it is defined
in '\packages\Facebook.6.1.4\lib\net40-client\Facebook.dll', but it
could not be
found \packages\FacebookWeb.5.4.1.0\lib\net40\Facebook.Web.dll
and the following error is produced on trying to run the program
Exception Details: System.TypeLoadException: Could not load type
'Facebook.FacebookApplication' from assembly 'Facebook,
Version=6.0.10.0, Culture=neutral, PublicKeyToken=58cb4f2111d1e6de'.
Source Error:
Line 12: public class HomeController : Controller
Line 13: {
Line 14: FacebookWebContext FBWebContext = new FacebookWebContext();
Line 15: FacebookWebClient FBWebClient = new FacebookWebClient();
Line 16:
I know this is a bit of an old one, but this may help someone else. Found the answer in the end. It was in the controller that I needed the following :-
var client = new FacebookClient(Session["FacebookToken"].ToString());
dynamic me = client.Get("me");
This got an active Token which allowed me to access the info again.

Resources