forked from Jonathan-Harker/API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefreshToken.py
68 lines (49 loc) · 1.7 KB
/
RefreshToken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import base64
import urllib.parse
import webbrowser
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
def EbayRefesh():
url = 'https://auth.ebay.com/oauth2/authorize'
clientid = "myclientid"
clientsecret = "myclientsecret"
uri = 'myuri'
key1 = "myUserName"
key2 = "myPassword"
scope = 'https://api.ebay.com/oauth/api_scope/sell.fulfillment'
payload = {'client_id':clientid, 'redirect_uri':uri, 'response_type':'code', 'scope':scope}
r = requests.get(url, params=payload)
driver = webdriver.Safari()
driver.get(r.url)
time.sleep(5)
actions = ActionChains(driver)
actions.send_keys(key1)
actions.send_keys(Keys.TAB)
actions.send_keys(key2)
actions.send_keys(Keys.ENTER)
actions.perform()
time.sleep(8)
code = driver.current_url
code = urllib.parse.unquote(code)
code = before, sep, after = code.rpartition("code=")
code = code[2]
code = before, sep, after = code.rpartition("&expires")
code = code[0]
# EbaAPI URL
url = "https://api.ebay.com/identity/v1/oauth2/token"
# Encode to base 64
B64 = clientid + ":" + clientsecret
B64e = base64.urlsafe_b64encode(bytes(B64, "utf-8"))
B64e = B64e.decode('ascii')
# Variables for headers
contentType = "application/x-www-form-urlencoded"
auth = "Basic " + B64e
# make the request
headers = {'Content-Type':contentType,'Authorization':auth}
data = {'grant_type':'authorization_code','code':code, 'redirect_uri':uri}
r = requests.post(url, headers=headers, data=data)
token = r.text
print(token)
EbayRefesh()