Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OAuth 2.0 authorization to Shopping API #369

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

xjxckk
Copy link

@xjxckk xjxckk commented Feb 17, 2022

Added OAuth 2.0 authorization to Shopping API.

Relevant issue: #347

@xjxckk xjxckk changed the title Add files via upload Added OAuth 2.0 authorization to Shopping API Feb 19, 2022
@paddisaap
Copy link

Can someone explain me where an how I have to implement this token?
Also where i can get this token from :O

@xjxckk
Copy link
Author

xjxckk commented May 12, 2022

You can install my fork, it will get the token for you.

If you want to do it yourself, you can read the discussion here: #347

@paddisaap
Copy link

paddisaap commented May 13, 2022

Thanks for the reply. I added your changes to the scripts but now i'm getting this:

Oauth2.0 token request response: {
    "error": "invalid_client",
    "error_description": "client authentication failed"
}
Traceback (most recent call last):
  File "/home/i430/VSCode/EBay Test API/ebaysdk new con file/finding-steuergeraete-61525.py", line 93, in <module>
    'IncludeSelector':'Details,Description,TextDescription,ShippingCosts,ItemSpecifics,Variations'})
  File "/home/i430/VSCode/EBay Test API/ebaysdk new con file/ebaysdk/connection.py", line 122, in execute
    self.build_request(verb, data, verb_attrs, files)
  File "/home/i430/VSCode/EBay Test API/ebaysdk new con file/ebaysdk/connection.py", line 141, in build_request
    headers = self.build_request_headers(verb)
  File "/home/i430/VSCode/EBay Test API/ebaysdk new con file/ebaysdk/shopping/__init__.py", line 183, in build_request_headers
    access_token = response_dict['access_token']
KeyError: 'access_token'

Any ideas how I can fix this?
And how do I have to configure my ebay.yaml file/ where do I have to put the OAuth Code in?

@xjxckk
Copy link
Author

xjxckk commented May 13, 2022

I updated the imports to include requests for POST.

This is my YAML file:

# Shopping API
open.api.ebay.com:
  appid: 
  devid: 
  certid: 

@dannyo1987
Copy link

@timotheus Do you think you could have a look at this? Just ran into this issue.

@springfielddatarecovery
Copy link

Would also like to see this feature implemented

@atmosse
Copy link

atmosse commented Jan 12, 2023

Thanks for the implementation! After reviewing this thread and implementing all suggestions, I generate the access token but end up running into this error:
image
I would appreciate any leads on how to fix this!

@xjxckk
Copy link
Author

xjxckk commented Jan 12, 2023

Looks like theres some kind of other error occuring, best to go into the source and add prints to see whats going on in your system. I haven't looked at the code for a while.

@dannyo1987
Copy link

@xjxckk's fork has a nice solution, but a couple minor bugs. I got a similar error and made a couple minor changes to the code he provided to get it working. Might try my fork.

@jswanson
Copy link

jswanson commented Feb 8, 2023

Any hope for this fix? Seems like a straight forward approach to solve a problem many people are dealing with.

@pbreezy20
Copy link

@dannyo1987 - can you provide a quick guide on how to use your fork? For example, I am looking to use the GetShippingCost function.

@dannyo1987
Copy link

You don't have to do anything other than install the fork as a dependency and set up your configuration with your app_id and cert_id

@dannyo1987
Copy link

dannyo1987 commented Mar 1, 2023

Someone at Ebay should really merge this @timotheus. This api is not that useful without this PR merged. And it's a really nice api, would hate to see it lose its utility!

@vaibhavbafna5
Copy link

vaibhavbafna5 commented Mar 9, 2023

atmosse

hey! i'm running into a similar issue - i'm able to generate my Oauth token successfully using the fork above + modifications, but when i make the request i get hit with a similar error. what did you do to resolve? pasting my approach below:

from ebaysdk.shopping import Connection as shopping

shopping_api = shopping(appid="XXX", config_file="ebay.yaml", debug=True)

response = shopping_api.execute('GetSingleItem', {
                'ItemID': item_id,
            })

print(response)

error:

2023-03-08 20:47:25,522 ebaysdk [DEBUG]:REQUEST (c9cf2d53-b4d9-474a-bb1c-668abc521816): POST https://open.api.ebay.com/shopping
2023-03-08 20:47:25,522 ebaysdk [DEBUG]:headers={'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic [oauth_token]', 'User-Agent': 'eBaySDK/2.2.0 Python/3.10.9 Darwin/20.3.0', 'X-EBAY-SDK-REQUEST-ID': 'c9cf2d53-b4d9-474a-bb1c-668abc521816', 'Content-Length': '152'}
2023-03-08 20:47:25,529 ebaysdk [DEBUG]:body=b'<?xml version=\'1.0\' encoding=\'utf-8\'?><GetSingleItemRequest xmlns="urn:ebay:apis:eBLBaseComponents"><ItemID>334451252528</ItemID></GetSingleItemRequest>'
2023-03-08 20:47:26,005 ebaysdk [DEBUG]:RESPONSE (c9cf2d53-b4d9-474a-bb1c-668abc521816):
2023-03-08 20:47:26,006 ebaysdk [DEBUG]:elapsed time=0:00:00.475940
2023-03-08 20:47:26,006 ebaysdk [DEBUG]:status code=404
2023-03-08 20:47:26,006 ebaysdk [DEBUG]:headers={'date': 'Thu, 09 Mar 2023 01:47:27 GMT', 'server': 'ebay-proxy-server', 'content-length': '0', 'x-envoy-upstream-service-time': '10', 'x-ebay-pop-id': 'UFES2-RNOAZ03-openapi'}
2023-03-08 20:47:26,006 ebaysdk [DEBUG]:content=
RESPONSE {'_content': b'', '_content_consumed': True, '_next': None, 'status_code': 404, 'headers': {'date': 'Thu, 09 Mar 2023 01:47:27 GMT', 'server': 'ebay-proxy-server', 'content-length': '0', 'x-envoy-upstream-service-time': '10', 'x-ebay-pop-id': 'UFES2-RNOAZ03-openapi'}, 'raw': <urllib3.response.HTTPResponse object at 0x103b252d0>, 'url': 'https://open.api.ebay.com/shopping', 'encoding': None, 'history': [], 'reason': 'Not Found', 'cookies': <RequestsCookieJar[]>, 'elapsed': datetime.timedelta(microseconds=475940), 'request': <PreparedRequest [POST]>, 'connection': <requests.adapters.HTTPAdapter object at 0x103aeff70>}
2023-03-08 20:47:26,007 ebaysdk [DEBUG]:response parse failed: Document is empty, line 1, column 1 (<string>, line 1)
Traceback (most recent call last):
  File "/Users/vaibhav/projects/playground/ebay/dummy.py", line 7, in <module>
    response = shopping_api.execute('GetSingleItem', {
  File "/Users/vaibhav/projects/playground/ebay/venv/lib/python3.10/site-packages/ebaysdk-2.2.0-py3.10.egg/ebaysdk/connection.py", line 129, in execute
    self.error_check()
  File "/Users/vaibhav/projects/playground/ebay/venv/lib/python3.10/site-packages/ebaysdk-2.2.0-py3.10.egg/ebaysdk/connection.py", line 222, in error_check
    estr = self.error()
  File "/Users/vaibhav/projects/playground/ebay/venv/lib/python3.10/site-packages/ebaysdk-2.2.0-py3.10.egg/ebaysdk/connection.py", line 338, in error
    error_array.extend(self._get_resp_body_errors())
  File "/Users/vaibhav/projects/playground/ebay/venv/lib/python3.10/site-packages/ebaysdk-2.2.0-py3.10.egg/ebaysdk/shopping/__init__.py", line 291, in _get_resp_body_errors
    if self.response.reply.Ack == 'Failure':
AttributeError: 'ResponseDataObject' object has no attribute 'Ack'

@martende
Copy link

I have the also issue with this branch :

2023-04-18 13:05:57,581 ebaysdk [DEBUG]:execute: verb=GetSingleItem data={'ItemID': '175690456463'}
{'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ......'} grant_type=client_credentials&scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope

Oauth2.0 token request response: {
    "error": "server_error",
    "error_description": "server encountered an unexpected condition that prevented it from fulfilling the request"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants