Posted by Anonymous on August 26, 2010 at 9:51pm
Next to my previous post, I've also created a small application for the Android platform.
It is called Drupal Power and with this app. users are able to post blog posts to their drupal site.
http://www.androidzoom.com/android_applications/social/drupal-power_hdcc...
Comments
Nice. Curious - why XMLRPC?
Rudy,
This is a nice proof of concept. I am curious though -- why the heavyweight XMLRPC instead of JSON? Were you accepting the heavier protocol to avoid the using the modified JSON server? I'm going down the JSON path, and rewrote the Drupal integration class I use in Flash to JavaScript. It's got some nice error handling features, but more importantly, JSON is a bit more lightweight.
John S.
I choose the xmlrpc indeed
I choose the xmlrpc indeed because of the modified json server. I just wanted a stable application without the modification / installing a custom service module. I agree that the xmlrpc is maybe not the right way, but it was the easiest for me
Cannot wait to get to either of these points you're discussing
JSON data is readily accesssible as JSON objects in your javascript. This compares to XML which must be parsed and assigned to variables using DOM API. But a bird in hand! Should be an easy conversion as time permits.
Don
Titanium Javascript source code?
Hi Rudy,
Could you please upload the Titanium Javascript source code for this project?
It would really help those of us who are still struggling with getting our first app up and running.
Thank you!!!
Rob
Here you go
http://pastie.org/1191355
Nice one, Thanks Rudy!
Nice one, Thanks Rudy!
Thanks Rudy!
This is great!!! Thank you :)
Vous etes impressionnant,
Vous etes impressionnant, Rudy!
Rudy did you figure out how
Rudy did you figure out how to get android to work with key authentication?
http://point-at-infinity.org/jssha256/
No not yet really, haven't
No not yet really, haven't tried it yet. Although, if you come up with a solution, or to change from xmlrpc to json service, that would be great.
http://blog.soniccode.com/php
http://blog.soniccode.com/php/drupal-connected-iphone-application-using-...
i got it to the point where i
i got it to the point where i wasn't getting any errors, but the view doesn't load either...
Drupal + JSON Server + HMAC Authentication + Titanium
I've consolidated a number of examples and tutorials to get this working. I hope it works for others out there too... (note my development/production enviroment below)
Major props to Rudy van der Blom, Sumit Kataria at CivicActions, Chris Callender at soniccode and Jingsheng Wang aka skyredwang (love the BeerCloud app!!!). Thanks also to @jaypark for the link to soniccode.
This is the Javascript that does the heavy lifting:
file: node_get_with_key_validation.js
// include the .js library for the HMAC-SHA256 message authentication code
// see: http://point-at-infinity.org/jssha256/ and dowload the library from the Download section on the page
Ti.include("jssha256.js");
// include your functions
// e.g. the randomString() function at: http://www.xinotes.org/notes/note/515/ (Method 2)
Ti.include("functions.js");
// provide the link to your JSON server
var JSONServer = 'http://www.yoursite.com/services/json'; // change 'www.yoursite.com' to your domain
// provide the API Key from your Drupal Services module
// you can create the key at /admin/build/services/keys
// use the www.yoursite.com format i.e. without http:// or /services/json
var apikey = 'b25217651ca131de655e0ef3963005fe'; // not my real key but yours will look similar to this
var win = Titanium.UI.currentWindow;
win.backgroundColor = '#656565';
var data = [];
var date = new Date();
var domain = 'www.yoursite.com'; // change this to your site's url. use the same format that you used when setting up the API Key at /admin/build/services/keys
var obj = {
method: 'node.get', // make sure that node.get is enabled for your API Key (navigate to /admin/build/services/keys and click the edit operation for your API key)
nid: 1, // set the node id (nid) here
domain_name: domain,
domain_time_stamp: String(date.getTime()), // need to convert the date/time to a string
nonce: randomString(10) // generate a random string, see: functions.js
};
// create the hash value
obj.hash = HMAC_SHA256_MAC(apikey, obj.domain_time_stamp+";"+obj.domain_name+";"+obj.nonce+";"+obj.method);
Ti.API.info(JSON.stringify(obj)); // displays the JSON object in the Titanium Developer console
// prepare Titanium to send the request via a HTTP Post method
var xhr = Titanium.Network.createHTTPClient();
xhr.open("POST", JSONServer);
xhr.send({data: JSON.stringify(obj)}); // send the JSON object to the JSON server
xhr.onload = function(){
Ti.API.info(this.responseText); // display the response from the JSON server in the Titanium console
var data = JSON.parse(this.responseText);
Ti.API.info(data); // display the node data
var label = Titanium.UI.createLabel({
color:'#fff',
text:data['title']+data['body'], // i've yet to format the output :)
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win.add(label);
}
Here's my modified app.js file:
var tabGroup = Titanium.UI.createTabGroup();
// the first tab containing a node from your site
var win1 = Titanium.UI.createWindow({
title:'Node for First Tab',
backgroundColor:'#fff',
url: 'node_get_with_key_validation.js'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'A Node',
window:win1
});
// the second tab...
var win2 = Titanium.UI.createWindow({
title:'Node for Second Tab',
backgroundColor:'#fff',
url: 'node_get_with_key_validation.js' // change as desired
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Another One',
window:win2
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.open();
...and the contents of the functions.js file:
// Generate a random string
// Source: http://www.xinotes.org/notes/note/515/ (Method 2)
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (! length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
Note: Pay particular attention to the versions of Services Module and JSON Server module as there are some incompatabilities across the versions and also check that your PHP is prior to 5.2.8 (Refer to skyredwang's comments at http://groups.drupal.org/node/57378)
My own technical setup is as follows...
Webserver: Linux 2.6.32.21-grsec, Apache 2.2.16, PHP 5.2.14, MySQL 5.0.91-community-log
Drupal: 6.19
Services module: 6.x-2.2
JSON Server module: Sumit's modified version at: http://civicactions.com/blog/2010/may/02/drupalcon_developing_apps_iphon... (refer to the file called json_server_modified.zip_.txt in the Attachment section)
Titanium SDK: 1.4.0
Titanium Developer: 1.2.1
Android SDK: APIs 1.6 with a WVGA854 screen
Any questions, feel free to ask...
Peace out,
Rob
Image upload
Thanks Rudy.
Could you please show us how you did for images uploading from mobile to Drupal .