使用PHP SDK创建新用户时出错

时间:2014-11-11 12:34:55

标签: php parse-platform

我目前在尝试使用PHP SDK创建新用户时遇到错误

  1. Parse Platform

  2. Post Image

  3. 错误输出

    You must specify a Parse class name or register the appropriate subclass when creating a new Object. Use ParseObject::create to create a subclass object.
    

    PHP文件

    $user = new ParseUser();
    $user->set("username", "test");
    $user->set("email", "test@gmail.com");
    $user->set("password", "Cf%09ude");
    
    try {
        $user->signUp();
        $result = true;
    } catch (ParseException $ex) {
        echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
    }
    

2 个答案:

答案 0 :(得分:0)

您无法使用ParseClient::initialize初始化SDK。加载autoload.php后的正确用法是:

use Parse\ParseClient;
use Parse\ParseUser;

$app_id = 'your_app_id';
$rest_key = 'your_rest_key';
$master_key = 'your_master_key';

ParseClient::initialize($app_id, $rest_key, $master_key);

$user = new ParseUser();
$user->set("username", "test");
$user->set("email", "test@gmail.com");
$user->set("password", "Cf%09ude");

try {
    $user->signUp();
    $result = true;
} catch (ParseException $ex) {
    echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
}

上面的代码已经过测试,并且使用了正确的API密钥 - 我能够通过注释掉ParseClient::initialize行来重现您的错误。我已submitted a Pull Request to GitHub为此方案显示更具描述性的例外情况。

答案 1 :(得分:0)

尝试:

$user= ParseUser::create('_User');

这是在the source中创建用户的方式。