简体   繁体   中英

Get salesforce.com access_token with django and REST-api

I try to authorize my account with salesforce using code:

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()

But still getting bad request error. What should I change?

Have you tried 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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM