Salesforce MobileSDK:未为此组织启用Rest API

Hou*_*fly 7 android salesforce

我正在尝试将Salesforce Mobile SDK用于原生Android.需求:

  1. 允许任何拥有Salesforce帐户的用户登录
  2. 获取他/她的联系人列表
  3. 获取特定联系人详细信息

如果这些不属于Mobile SDK,请告知我们.

我关注https://github.com/forcedotcom/SalesforceMobileSDK-Android:

  1. 克隆它
  2. 安装NPM并安装所需的子模块
  3. 使用原生的forceroid创建了一个新的Android应用程序
  4. bootconfig.xml使用我连接的应用程序的值更改了值.

它记录正常,但当我尝试获取联系人时,它说:

未为此组织启用Rest API

在此输入图像描述

登录响应似乎没问题.客户端对象json凭据:

{
  "clientId": "*******",
  "loginUrl": "https://login.salesforce.com",
  "identityUrl": "https://login.salesforce.com/id/99VVHJHGF5688/00548000003yOKeAAM",
  "instanceUrl": "https://ap2.salesforce.com",
  "userId": "**********",
  "orgId": "*********",
  "communityUrl": null,
  "refreshToken": "*************",
  "accessToken": "************",
  "communityId": null,
  "userAgent": "SalesforceMobileSDK/4.3.0 android mobile/7.0 (Nexus 6P) SFTest/1.0 Native uid_32aea9bdde1b8b7e"
}
Run Code Online (Sandbox Code Playgroud)

编辑1:获取联系人列表的代码:

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
    sendRequest("SELECT Name FROM Contact");
}

private void sendRequest(String soql) throws UnsupportedEncodingException {
    RestRequest restRequest = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(this), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() {
        @Override
        public void onSuccess(RestRequest request, final RestResponse result) {
            result.consumeQuietly(); // consume before going back to main thread
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        listAdapter.clear();
                        JSONArray records = result.asJSONObject().getJSONArray("records");
                        for (int i = 0; i < records.length(); i++) {
                            listAdapter.add(records.getJSONObject(i).getString("Name"));
                        }
                    } catch (Exception e) {
                        onError(e);
                    }
                }
            });
        }

        @Override
        public void onError(final Exception exception) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(MainActivity.this,
                            MainActivity.this.getString(SalesforceSDKManager.getInstance().getSalesforceR().stringGenericError(), exception.toString()),
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

编辑2:更多的发现:

我认为这与我的帐户/已连接的应用设置有关.因为当我使用https://developer.salesforce.com/signup进行 signedup 并使用username它时工作正常.在这里,如果我使用它email而不是它显示相同的API错误未启用.我创建了多个 username使用相同email和注册表单,他们都工作正常,但不是电子邮件.

BTW我目前正在使用salesforce的试用版.

sup*_*ell 1

常规试用帐户适用于专业版,不包括 API 访问,这是您收到的错误。您需要使用具有 API 访问权限的帐户,例如免费开发者版帐户或企业版帐户。