I am trying to experiment with the Stack Overflow API on my localhost and am struggling to get the authentication to complete. Here is my application JavaScript code (note that I am using IBM Worklight, hence the wl
functions):
function wlCommonInit(){
// Common initialization code goes here
SE.init({
clientId: 4299,
key: 'Dj9*ZH87BW6Q2hatei2mKw((',
channelUrl: 'http://localhost:10080/',
complete: function(data){
console.log(data);
}
});
}
$('#submitButton').click(function(){
SE.authenticate({
success: function(data){
var link='https://api.stackexchange.com/docs/answers#order=desc&sort=activity&filter=default&site=stackoverflow';
$.getJSON(link+'?callback=?',function(json) {
if(json.length!=0){
console.log(json);
$('h1').insert(json);
}
});
},
error: function(data){
$('h1').insert("Authentication error");
},
scope: []
});
});
Essentially I am trying to return a JSON object using the \answers
method.
I have set the OAUTH domain on the App page to localhost
. When I deploy the app to the worklight development server and press the #submitButton
, I get the following message:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost') does not match the recipient window's origin ('http://localhost:10080').
I have tried numerous potential fixes from discussion forums, but nothing seems to work.
SE.authenticate()
.