【问题标题】:SetReadAccess error for new ParseObject新 ParseObject 的 SetReadAccess 错误
【发布时间】:2014-09-17 01:50:25
【问题描述】:

我在我的一个 Android 应用程序的应用程序类中放置了以下代码:

// Register ParseObject subclasses
ParseObject.registerSubclass(Results.class);

// Set up Parse
Parse.enableLocalDatastore(MyApplication.this);
Parse.initialize(MyApplication.this, PARSE_APP_KEY, PARSE_CLIENT_KEY);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

每当我重新安装我的应用程序并创建新的结果对象时,这似乎工作得很好。现在,如果我通过 Play 商店更新我的应用程序,或通过 Android Studio 安装它,每当创建新的 Results 对象或任何其他 ParseObject 或其子类时,我都会收到以下错误:

java.lang.IllegalArgumentException: cannot setReadAccess for a user with null id

这是 Parse 的错误吗?我在离线 Todo 示例中得到了相同的结果。

【问题讨论】:

  • 在我看来,ParseUser.enableAutomaticUser() 不允许设置 ACL - 我不知道为什么,因为我没有使用自动用户功能
  • 奇怪的是,在我更新它或用另一个开发版本覆盖安装之前,应用程序中一切正常(创建 ParseObjects 时没有 ACL 错误)。

标签: android parse-platform acl


【解决方案1】:

您需要确保保存当前用户。

// Register ParseObject subclasses
ParseObject.registerSubclass(Results.class);

// Set up Parse
Parse.enableLocalDatastore(MyApplication.this);
Parse.initialize(MyApplication.this, PARSE_APP_KEY, PARSE_CLIENT_KEY);
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground(); // <--- This Line
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);

不完全确定我的语法,我只在 Swift 中做过。

【讨论】:

  • 当我尝试这样做时,我得到一个不同的错误:IllegalArgumentException: Cannot save a ParseUser until it has been signed up. Call signUp first. 我的目标是将解析数据存储为匿名用户,直到用户想要注册。然后允许保存到云端。
  • 在我的应用程序上,我没有调用注册,它工作正常。你可以匿名注册吗?
  • 没关系,我说得太早了。在尝试该代码之前,我没有完全卸载该应用程序。现在,如果我安装在以前的版本上,它似乎可以工作。谢谢!
【解决方案2】:

从设备中删除应用程序,然后重新安装。它应该工作。

这是我的设置

    //Parser App Crash Report
    ParseCrashReporting.enable(this); //THIS is to test only =>  throw new RuntimeException("Test Exception!");

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    // Initialise
    Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);


    ParseUser.enableAutomaticUser();
    ParseUser.getCurrentUser().saveInBackground();
    ParseACL defaultACL = new ParseACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.setPublicReadAccess(true);

    ParseACL.setDefaultACL(defaultACL, true);

然后用 :

测试
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.put("2", "2");
testObject.put("3", "3");
testObject.saveInBackground();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多