1

编辑:我找到了解决方案。

问题是 QBUsers:signUp 不执行用户登录。所以你(和我)应该在 QBUsers:signUp 之后做 QBUsers:logIn

首先,如果用户不存在,我会登录我的用户或注册。我的代码:

    qbUser = [QBUUser user];
    qbUser.fullName = @"some name";
    qbUser.login = @"40118285";
    qbUser.password = @"worldvideovoyage";
    ...
    [QBUsers logInWithUserLogin:qbUser.login password:qbUser.password delegate:self];

如果用户还不存在,我会执行唱起用户:

-(void)completedWithResult:(Result *)result
{
    if(!result.success) {
        ASLog(@"%@", result.errors);
    }
    if([result isKindOfClass:QBUUserLogInResult.class]) {
        if(result.success) {
            QBUUserLogInResult *res = (QBUUserLogInResult*)result;
            qbUser = res.user;
            ASLog(@"LogIn user %@ completed", qbUser.email);
            [self.params loadWithUserID:qbUser.ID];
        } else {
            // we have to signup firstly
            ASLog(@"Signup user %@", qbUser.login);
            [QBUsers signUp:qbUser delegate:self];
        }
    } else if([result isKindOfClass:QBUUserResult.class]) {
        if(result.success) {
            QBUUserResult *res = (QBUUserResult*)result;
            qbUser = res.user;
            ASLog(@"Signup user %@ completed", qbUser.email);
            [self.params saveWithUserID:qbUser.ID];
            [[NSNotificationCenter defaultCenter] postNotificationName:nCHANGE_USER object:self];

        } else {
            // signup fails
            ASLog(@"ERROR: signup fail!");
        }
    }
}

之后我在控制台中:

2013-09-10 13:49:42.109 DimChat[48347:1b27] Request finished, response: 
RestResponse:
------
<QBASIHTTPRequest: 0xe275400>
headers:{
    "Access-Control-Allow-Headers" = "QB-Token,QuickBlox-REST-API-Version";
    "Access-Control-Allow-Origin" = "*";
    "Access-Control-Request-Method" = "*";
    "Cache-Control" = "max-age=0, private, must-revalidate";
    Connection = Close;
    "Content-Length" = 623;
    "Content-Type" = "application/xml; charset=utf-8";
    Date = "Tue, 10 Sep 2013 09:49:39 GMT";
    Etag = "\"9973e1c39deddfd236cab1a0de3e4b38\"";
    Location = "http://api.quickblox.com/users/503563";
    "QB-Token-ExpirationDate" = "2013-09-10 11:49:39 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.0.15";
    Status = "201 Created";
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 6c8eddea8a6f7b6c03e6eb02d40472a3;
    "X-Runtime" = "0.083159";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<user>
  <blob-id type="integer" nil="true"/>
  <created-at type="datetime">2013-09-10T09:49:39Z</created-at>
  <email nil="true"/>
  <external-user-id type="integer" nil="true"/>
  <facebook-id nil="true"/>
  <full-name>ÐаÑилий ÐакаÑов</full-name>
  <id type="integer">503563</id>
  <last-request-at type="datetime" nil="true"/>
  <login>40118285</login>
  <owner-id type="integer">4855</owner-id>
  <phone nil="true"/>
  <twitter-id nil="true"/>
  <updated-at type="datetime">2013-09-10T09:49:39Z</updated-at>
  <website nil="true"/>
  <user-tags nil="true"/>
</user>

error:
2013-09-10 13:49:42.110 DimChat[48347:c07] -[ASUser completedWithResult:] [Line 262] Signup user (null) completed

然后我尝试创建 QBCOCustomObject:

co = [QBCOCustomObject customObject];
co.className = @"Settings";
co.userID = userID;
co.fields[@"goal"] = [NSNumber numberWithInt:_goal];
// ... init other fields of custom object
[QBCustomObjects createObject:co delegate:self];

我得到一个错误:

2013-09-10 13:50:11.135 DimChat[48347:cb0f] Request finished, response: 
RestResponse:
------
<QBASIHTTPRequest: 0xe275400>
headers:{
    "Access-Control-Allow-Headers" = "QB-Token,QuickBlox-REST-API-Version";
    "Access-Control-Allow-Origin" = "*";
    "Access-Control-Request-Method" = "*";
    "Cache-Control" = "no-cache";
    Connection = Close;
    "Content-Length" = 97;
    "Content-Type" = "application/xml; charset=utf-8";
    Date = "Tue, 10 Sep 2013 09:50:08 GMT";
    "QB-Token-ExpirationDate" = "2013-09-10 11:49:39 UTC";
    "QuickBlox-REST-API-Version" = "0.1.1";
    Server = "nginx/1.0.15";
    Status = "422 Unprocessable Entity";
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 081ee974feacc97e8af6a2c53e1795da;
    "X-Runtime" = "0.031358";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<errors>
  <error>Forbidden. Need user.</error>
</errors>

我很确定我有有效的 QBUUser 并且我执行了登录。但是为什么我有这个错误?

4

1 回答 1

3

我找到了解决方案。

问题是 QBUsers:signUp 不执行用户登录。所以你(和我)应该在 QBUsers:signUp 之后做 QBUsers:logIn

于 2013-09-11T07:09:33.640 回答