1

我正在使用 Gigya 作为我的 iOS 应用程序的单点登录系统。它是集成的,我可以使用 Twitter、Facebook 和手动电子邮件注册登录。

由于 Facebook 和 Twitter 都不返回手机号码,因此我在成功注册/登录后附加此信息以及电子邮件等其他信息。我能够成功更新个人资料中的字段,例如用户名、昵称等,但不能更新电话。

可以在此处找到配置文件结构的描述:http: //developers.gigya.com/020_Client_API/020_Accounts/010_Objects/Profile

所以我想发帖: {@"phones": @[@{@"number" : _phoneNumberTextfield.text}]}

作为个人资料内容。这显然没问题,因为响应的 statusReason OK。

一切都好,如果我添加其他字段,它们就会更新。但是当我检索个人资料时,那里没有电话号码。我尝试根据定义附加字段“类型”,但后来我得到:400025 写入访问验证错误。

所以更新调用告诉我一切正常,但它没有将数字附加到配置文件中。将类型添加到 @"phones" 数组中的每个数字条目会导致访问冲突。

我浏览了 Gigya 的 API 规范,找不到任何工作示例,甚至找不到这种情况的 JSON 示例;有人对此有解决方案吗?

4

2 回答 2

1

服务器端的 Gigya SDK 将数据表示为 JSON 对象,它能够表示键或数组下的嵌套对象。

对于帐户上的“profile.phone”属性,它存储为对象数组,如下所述:

{
    "profile": {
        "phones": [
            { "type": "phone", "number": "8005551234" },
            { "type": "cell", "number": "8885551234" }
        ]
    }
}

通常,在使用 Gigya 的 iOS API 时,通常将这些 JSON 概念分别映射到 NSMutableDictionary 和 NSMutableArray 类,然后使用 NSJSONSerialization 类对数据进行序列化。

因此,例如,如果我们想在 Gigya 的帐户上设置电话号码,如上所示,那么您需要使用以下代码来完成此操作:

    NSMutableDictionary *phone1 = [NSMutableDictionary dictionary];
    [phone1 setObject:@"phone" forKey:@"type"];
    [phone1 setObject:@"8005551234" forKey:@"number"];

    NSMutableDictionary *phone2 = [NSMutableDictionary dictionary];
    [phone2 setObject:@"cell" forKey:@"type"];
    [phone2 setObject:@"8885551234" forKey:@"number"];

    NSMutableArray *phones = [NSMutableArray array];
    [phones addObject:phone1];
    [phones addObject:phone2];

    NSMutableDictionary *profile = [NSMutableDictionary dictionary];
    [profile setObject:phones forKey:@"phones"];

    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:profile
                                                       options:0
                                                         error:&error];

    GSRequest *request = [GSRequest requestForMethod:@"accounts.setAccountInfo"];
    [request.parameters setObject:jsonString forKey:@"profile"];
    [request sendWithResponseHandler:^(GSResponse *response, NSError *error) {
        if (!error) {
            NSLog(@"Success");
            // Success! Use the response object.
        }
        else {
            NSLog(@"error");
            // Check the error code according to the GSErrorCode enum, and handle it.
        }
    }];

或者,您可以直接构造一个 JSON 字符串;但是对于添加新属性时需要进行的任何更改,上述策略往往更加灵活。

于 2015-03-20T21:58:17.557 回答
1

如果您使用 accounts.getAccountInfo 检索配置文件,请确保包含“extraProfileFields = 电话”参数。手机数组默认不会返回。

http://developers.gigya.com/037_API_reference/020_Accounts/accounts.getAccountInfo

于 2015-03-21T01:11:06.797 回答