CreateUser example for Marmalade

0 votes

HI,

 

 

I could not get the following code snipper to work in my Marmalade project. (taken from http://api.shephertz.com/app42-docs/user-management-service/)

  1. userService->CreateUser(userName, pwd, emailId,this,app42callfuncND_selector(Sample_Class::onUserRequestCompleted));  
  2. void Sample_Class::onUserRequestCompleted(App42CallBack *sender, void *response)  

 

Specifically, I have a type mismatch error for the pTarget argument ("this"). If I pass a NULL value, the line executes but does not create a user.

userService->CreateUser(userName, pwd, emailId,NULL, SEL_App42CallFuncND(MainMenu::onUserRequestCompleted));

Can someone send me working C++ code snippet that uses the above API call?

asked Dec 21, 2014 in App42 Cloud API-BaaS by siva (10 points)

1 Answer

0 votes

Hello Siva,

 

The error which you have shared is occur due to wrong value passed in 4th  parameter of method. The fourth parameter hold the value of App42CallBack class reference. To make it work, kindly pass "new App42CallBack()" as a value at 4th parameter, it will resolve your issue.

Kindly check & let us know if it helps.

Himanshu Sharma

answered Dec 22, 2014 by hs00105 (2,005 points)
Well, it looks like the fourth parameter should be the instance of the class that the callback needs to return to. "this" worked as long as I derive the containing class from App42CallBack(). The code compiles and executes, but still does not create the user in the App42 Cloud Control panel. And the callback function isn't being called either. The code snippets are presented below:

Thanks!

class User : public App42CallBack

void User::CreateUser(std::string userName, std::string pwd, std::string emailId) {
    App42API::Initialize("realapikey", "realsecretkey");
    UserService *userService = App42API::BuildUserService();
    userService->CreateUser(userName.c_str(), pwd.c_str(), emailId.c_str(), this, SEL_App42CallFuncND(&User::onUserRequestCompleted));
}

void User::onUserRequestCompleted(App42CallBack *sender, void *response)
{
    App42UserResponse *userResponse = (App42UserResponse*)response;
    printf("\ncode=%d...=%d", userResponse->getCode(), userResponse->isSuccess);
    printf("\nResponse Body=%s", userResponse->getBody().c_str());
    if (userResponse->isSuccess)
    {
        for (std::vector<App42User>::iterator it = userResponse->users.begin(); it != userResponse->users.end(); ++it)
        {
            printf("\n UserName=%s", it->userName.c_str());
            printf("\n Email=%s", it->email.c_str());
            printf("\n SessionId=%s", it->sessionId.c_str());
            printf("\n isAccountLocked=%d", it->isAccountLocked);
            printf("\n CreatedOn=%s", it->createdOn.c_str());
        }
    }
    else
    {
        printf("\nerrordetails:%s", userResponse->errorDetails.c_str());
        printf("\nerrorMessage:%s", userResponse->errorMessage.c_str());
        printf("\nappErrorCode:%d", userResponse->appErrorCode);
        printf("\nhttpErrorCode:%d", userResponse->httpErrorCode);
    }
}
Hello Siva,
Its look like something is missing because we have tested the same at our end and its working fine. Could you please share your sample project with us at support@shephertz.com. It will help us to debug your issue & resolve it on asap.
Thanks,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...