Advertisement
Guest User

Untitled

a guest
Jan 17th, 2024
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. import requests
  6. import json
  7.  
  8. # eBay API credentials (replace with your own)
  9. APP_ID = 'YOUR_APP_ID'
  10. CERT_ID = 'YOUR_CERT_ID'
  11. DEV_ID = 'YOUR_DEV_ID'
  12. RU_NAME = 'YOUR_REDIRECT_URI'
  13. USER_TOKEN = 'YOUR_USER_TOKEN'
  14.  
  15. # eBay API endpoints
  16. AUTH_ENDPOINT = 'https://api.ebay.com/identity/v1/oauth2/token'
  17. API_ENDPOINT = 'https://api.ebay.com/sell/inventory/v1/inventory_item'
  18.  
  19. # Generate the OAuth2 token
  20. def get_oauth_token():
  21. headers = {
  22. 'Content-Type': 'application/x-www-form-urlencoded',
  23. }
  24. data = {
  25. 'grant_type': 'authorization_code',
  26. 'code': USER_TOKEN,
  27. 'redirect_uri': RU_NAME,
  28. }
  29. auth = (APP_ID, CERT_ID)
  30. response = requests.post(AUTH_ENDPOINT, headers=headers, data=data, auth=auth)
  31. response_json = response.json()
  32. return response_json['access_token']
  33.  
  34. # Create a function to list an item
  35. def list_item(access_token):
  36. headers = {
  37. 'Authorization': f'Bearer {access_token}',
  38. 'Content-Type': 'application/json',
  39. }
  40. item_details = {
  41. # Replace with your item details
  42. 'title': 'Your Item Title',
  43. 'description': 'Your Item Description',
  44. 'price': {
  45. 'currency': 'USD',
  46. 'value': '100.00', # Replace with your item price
  47. },
  48. # Add other item details as needed
  49. }
  50. payload = json.dumps(item_details)
  51. response = requests.post(API_ENDPOINT, headers=headers, data=payload)
  52. return response
  53.  
  54. def main():
  55. try:
  56. access_token = get_oauth_token()
  57. response = list_item(access_token)
  58. if response.status_code == 200:
  59. print("Item listed successfully!")
  60. else:
  61. print("Error:", response.status_code)
  62. print(response.text)
  63. except Exception as e:
  64. print("An error occurred:", str(e))
  65.  
  66. if __name__ == "__main__":
  67. main()
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement