0

I'm trying to get the Amazon advertising data using the Amazon Advertising API. I have to open a specific link: "https://www.amazon.com/ap/oa?client_id=...&scope=cpc_advertising:campaign_management&response_type=code&redirect_uri=https://.../" , that redirects me to an url where I can give my Login data.

To get that redirect url, I am using the BeautifulSoup in Python. In the Web Inspector I see that the redirect url is in the response headers under the name "location", yet when called with the BeautifulSoup, the "location" is missing.

from bs4 import BeautifulSoup

headers = {'user-agent': 'Thats the User Agent I get from the Web Inspector'}

p = requests.get(
    'Thats the link from which I wll be further redirected')

login_data = {
    'appAction': 'SIGNIN',
    'email': '...',
    'password': '...'
}

with requests.Session() as s:
    url = p.url
    r = s.get(url, headers=headers)
    soup = BeautifulSoup(r.content, 'html.parser')
    login_data['appActionToken'] = soup.find('input', attrs={'name': 'appActionToken'})['value']
    login_data['openid.return_to'] = soup.find('input', attrs={'name': 'openid.return_to'})['value']
    login_data['prevRID'] = soup.find('input', attrs={'name': 'prevRID'})['value']
    login_data['workflowState'] = soup.find('input', attrs={'name': 'workflowState'})['value']
    r = s.post(url, data = login_data, headers=headers)


    print(r.content)

Any ideas from where we can get the redirect urls ?

1 Answers1

0

Youself are the master of your application. You have to know the redirect url for your application and set it in the Login-with-Amazon console. You can set multiple redirect urls for each application in the console.

Something like:

https://www.yourpage.com/login
http://localhost:8080/login

See also: https://advertising.amazon.com/API/docs/en-us/setting-up/generate-api-tokens

tector
  • 977
  • 1
  • 8
  • 31