Android to Drupal user creation
For anyone who might need help creating a Drupal user from an Android app, the following code works:
//create a new HttpClient and post header
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://test.site.com/testpoint/user/register");
// TODO Auto-generated method stub
try{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add( new BasicNameValuePair("account[pass]", "cutelady"));
nameValuePairs.add( new BasicNameValuePair("account[mail]", "scarter@sgc.gov"));
nameValuePairs.add( new BasicNameValuePair("account[name]", "Samantha Carter"));
httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP post request
HttpResponse response = httpClient.execute(httpPost);
}catch(Exception e){
Log.e("HTTP ERROR", e.toString());
}
开发者_如何转开发However, I have an additional problem: when using the profile module to provide additional custom CCK fields for the user registration process, I can't find the right account[cck_parameter]
to connect and save my Android data to the profile CCK field.
What can I try to resolve this?
User is a user object and extra profile values are node objects. So the user_save function is designed to accept few params. The key is, you can create user profiles overriding "required field" status of the user/register form. Keep the current form, and try to create a new node too, after saving the user object.
See content profile API to see how to save(it's a node_save() ) a content profile.
精彩评论