For a number of days I have been looking into the possibility of integrating Twitter functionality for posting a high-score with a screenshot into a game that I am developing with CocoonJS. CocoonJS doesn't provide this functionality out of the box (although, it does for Facebook). I have been looking at OAuth and have experimented with trust trying to get the application to be able to present the user with a login. This was successful via the browser. The code used for this is:
test1 = function() {
var tempLogo = "<base64EncodedImg>";
OAuth.initialize("<public key>", {cache:true});
OAuth.popup("twitter").then(function(result) {
var data = new FormData();
data.append('status', 'This is a test');
data.append('media[]', Utils.b64toBlob(tempLogo), 'logo.png');
return result.post('/1.1/statuses/update_with_media.json', {
data: data,
cache:false,
processData: false,
contentType: false
});
}).done(function(data){
var str = JSON.stringify(data, null, 2);
console.log("Success: " + str);
}).fail(function(e){
var errorTxt = JSON.stringify(e, null, 2);
console.log("Success: " + errorTxt);
});
}
But when testing via CocoonJS launcher, I got the following error:
IDTK_LOG_ERROR: [JS] Invoked in void ludei::js::utils::JSUtilities::PrintException line 95: JavaScript Exception (Line: 1337 Tag: 'touchend'): TypeError: undefined is not an object (evaluating 'this.document.cookie.split')
On the device, the pop-up didn't appear.
I then tried to have a look at using hello.js. Again I was able to get their demo up and running very quickly in my game when I ran it in the browser. I used the following code:
test2 = function() {
hello.init({
'twitter' : '<twitter client id>'
},
{
redirect_uri:'redirect.html',
});
// Twitter instance
var twitter = hello('twitter');
// Login
twitter.login().then( function(r){
// Get Profile
return twitter.api('me');
}, "LOG" )
.then( function(p){
// Put in page
document.getElementById('login').innerHTML = "<img src='"+ p.thumbnail + "' width=24/>Connected to "+ 'twitter'+" as " + p.name;
}, "LOG" );
}
This then gave me a repeating error:
IDTK_LOG_ERROR: [JS] Invoked in void ludei::js::utils::JSUtilities::PrintException line 95: JavaScript Exception (Line: 13 Tag: 'timer'): TypeError: undefined is not an object (evaluating 'e.value.length')
On the device, the screen went black apart from a small logo, which I remember seeing being part of the pop-up asking for authentication that did work when I test this functionality on the desktop browser.
These error messages don't really mean much to me, and unfortunately I am not able to debug CocoonJS when I run the app on iOS (via CocoonJS Launcher) as this functionality i only present on Android.
Would just like to know whether what I am trying to achieve has been done by anybody in CocoonJS and whether or not what I am requesting is actually possible, and obviously how to get it working! =)
Any help would be much appreciated.
Thanks Rich