Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- # eBay API credentials (replace with your own)
- APP_ID = 'YOUR_APP_ID'
- CERT_ID = 'YOUR_CERT_ID'
- DEV_ID = 'YOUR_DEV_ID'
- RU_NAME = 'YOUR_REDIRECT_URI'
- USER_TOKEN = 'YOUR_USER_TOKEN'
- # eBay API endpoints
- AUTH_ENDPOINT = 'https://api.ebay.com/identity/v1/oauth2/token'
- API_ENDPOINT = 'https://api.ebay.com/sell/inventory/v1/inventory_item'
- # Generate the OAuth2 token
- def get_oauth_token():
- headers = {
- 'Content-Type': 'application/x-www-form-urlencoded',
- }
- data = {
- 'grant_type': 'authorization_code',
- 'code': USER_TOKEN,
- 'redirect_uri': RU_NAME,
- }
- auth = (APP_ID, CERT_ID)
- response = requests.post(AUTH_ENDPOINT, headers=headers, data=data, auth=auth)
- response_json = response.json()
- return response_json['access_token']
- # Create a function to list an item
- def list_item(access_token):
- headers = {
- 'Authorization': f'Bearer {access_token}',
- 'Content-Type': 'application/json',
- }
- item_details = {
- # Replace with your item details
- 'title': 'Your Item Title',
- 'description': 'Your Item Description',
- 'price': {
- 'currency': 'USD',
- 'value': '100.00', # Replace with your item price
- },
- # Add other item details as needed
- }
- payload = json.dumps(item_details)
- response = requests.post(API_ENDPOINT, headers=headers, data=payload)
- return response
- def main():
- try:
- access_token = get_oauth_token()
- response = list_item(access_token)
- if response.status_code == 200:
- print("Item listed successfully!")
- else:
- print("Error:", response.status_code)
- print(response.text)
- except Exception as e:
- print("An error occurred:", str(e))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement