Salesforce Oauth状态代码302

时间:2013-04-10 05:33:22

标签: salesforce oauth-2.0 httpresponse

尝试在组织中设置oauth时,获取状态代码302 以下是代码段。

String AUTH_URL   = 'https://login.salesforce.com/services/oauth2/authorize';
String redirect_uri = 'https://login.salesforce.com/services/oauth2/success';
String response_type = 'token';
String client_id = 'xxxxxxxxxxxxxx.xxxxxxxxx';

authURL = AUTH_URL + 
         '?response_type=' + response_type + 
         '&client_id=' + client_id + 
         '&redirect_uri=' + redirect_uri;

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http(); 

req.setMethod('GET'); 
req.setEndpoint(authUrl);   
res = http.send(req);

//结果:

res.getStatusCode()= 302
res.getStatus()=发现

我希望在响应的正文中接收访问令牌和刷新令牌,但它是空的 如果我错过了什么,请建议 提前致谢。

1 个答案:

答案 0 :(得分:0)

授权端点用于基于浏览器的交互式登录,而不是编程登录。如果你想要一个纯粹的程序方法,那么你应该检查你可以通过/ services / oauth2 / token端点使用的用户名/密码oauth流。