2016-10-03 46 views
7

我正在嘗試將Salesforce Mobile SDK用於本機Android。 要求:Salesforce MobileSDK:該組織未啓用Rest API

  1. 允許與Salesforce帳戶的用戶登錄
  2. 取他/她的聯繫人列表
  3. 獲取特定的聯繫方式

請讓我知道,如果這些不屬於Mobile SDK的一部分。

我也跟着https://github.com/forcedotcom/SalesforceMobileSDK-Android

  1. 將其克隆
  2. 安裝NPM和安裝所需的子模塊
  3. 創建使用本地forcedroid
  4. 一個新的Android應用程序的價值觀改變了bootconfig.xml值我連接的應用程序。

它記錄在正常,但當我嘗試獲取觸點,它說:

的REST API未對本組織

enter image description here

啓用登錄響應似乎很好。客戶對象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" 
} 

編輯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(); 
       } 
      }); 
     } 
    }); 
} 

編輯2:一些更多的發現:

我認爲它有使用我的帳戶/連接的應用程序設置。因爲 當我signedup使用https://developer.salesforce.com/signup和使用 username它工作正常。這裏再次如果我使用email而不是 它顯示API未啓用相同的錯誤。我創建了多個 username s使用相同的email和註冊表單,他們都工作 罰款,但不是電子郵件。

順便說一句我目前正在使用salesforce的試用版。

+0

我想你已經把JsonArrayRequest提供給了API。 –

+0

@Bansal請求代碼由SDK生成,因此它是標準的。 – Housefly

+0

也許嘗試使用Salesforce的Android本機樣例應用程序之一https://github.com/forcedotcom/SalesforceMobileSDK-Android/tree/master/native/NativeSampleApps/RestExplorer –

回答

1

定期試用帳戶是專業版,它不包含API訪問權限,這是您收到的錯誤。您需要使用具有API訪問權限的帳戶,例如免費開發者版帳戶或企業版帳戶。

+0

因此,如果我的https://www.salesforce.com/form/signup/freetrial -sales.jsp帳戶已付款且擁有連接的應用程序,與我的Android應用程序集成後,任何擁有salesforce帳戶的用戶都可以登錄並訪問這些API?我只是想確保它不必是一個開發者帳戶。 – Housefly

+0

您正在爲您的公司的salesforce用戶構建應用程序嗎?還是您正在爲其他公司的salesforce用戶構建應用程序?合作伙伴或ISV情況]? – superfell

+0

**不適用於「我的公司用戶」。理想情況下,任何公司的任何Salesforce用戶都應該能夠通過我的Android應用程序登錄並使用這些API。 – Housefly

相關問題