我正在尝试使用适用于 native Android的Salesforce Mobile SDK。
要求:
如果这些不是移动SDK的一部分,请告诉我。
我关注了https://github.com/forcedotcom/SalesforceMobileSDK-Android:
它登录正常,但是当我尝试获取联系人时,它说:
登录响应似乎很好。客户端对象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:其他一些发现:
最佳答案
常规试用帐户适用于专业版,该版本不包含API访问权限,这是您遇到的错误。您需要使用具有API访问权限的帐户,例如免费的开发人员版帐户或企业版帐户。