如何将Salesforce OAuth连接到另一个salesforce组织

时间:2013-12-20 09:36:22

标签: javascript rest oauth-2.0 salesforce visualforce

我已经创建了一个POST方法REST服务,并试图在visualforce页面中通过JavaScript中的sforce.connection.remoteFunction调用该服务。

 var request_url = 'https://test.salesforce.com/services/oauth2/token';
 var result = sforce.connection.login("myloginid@mymail.com", "mypassword+mysecurityToken");

此处的登录ID,密码和安全令牌与我必须用于登录salesfroce帐户的ID和密码不同

 var sessionId= sforce.connection.sessionId;  
 sforce.connection.init(sessionId, request_url);

 sforce.connection.remoteFunction({

 url : request_url,
 type : "post",
 async : false,
 requestHeaders: {"Authorization":"Bearer "+sessionId, "Content-Type":"application/json","Connection":"Keep-Alive"},

            data :requestData,          
            onSuccess : function(response) {
                console.log(success);
            },
            onFailure: function(response) {
               console.log(response.responseText);

                 }
        });

但是回复是错误401未经授权。我的请求中是否有任何遗漏?

我已经看到了两个解决方案: -

1。https://salesforce.stackexchange.com/questions/17382/apex-rest-api-call-from-javascript-via-ajax-toolkit?rq=1

2。https://salesforce.stackexchange.com/questions/13607/how-to-call-apex-rest-api-from-javascript

但这些解决方案对我不起作用。请帮帮我..

0 个答案:

没有答案