2012-05-15 39 views
1

嘗試授權使用Salesforce使用代碼我的帳戶:獲取salesforce.com用的access_token Django和REST的API

data = { 
    'client_id': settings.CONSUMER_KEY, 
    'client_secret': settings.CONSUMER_SECRET, 
    'redirect_uri': 'https://DOMAIN.com/salesforce/auth/', 
    'grant_type': 'authorization_code', 
} 
data = urllib.urlencode(data) 
result = urllib2.urlopen('https://SALESFORCEDOMAIN.com/services/oauth2/token', data).read() 

但仍然得到錯誤的請求錯誤。我應該改變什麼?

+0

你在說你的授權類型是授權碼,但你看起來並沒有在請求中包含代碼。 – superfell

回答

1

您是否嘗試過httplib2?

from httplib2 import Http 
from urllib import urlencode 
head = Http() 
data = dict(name="Whatever", stuff="Hey you") 
response, content = head.request("http://domain.com/etc", "METHOD", urlencode(data)) 
+0

我會檢查它:) – szaman