Hi,
I need to access song previews through the API. I learned from
this page that it now requires OAuth signed requests. Since I'm using Python, I tried
rauth and
requests-oauthlib for this by following the examples on their respective GitHub pages.
In the case of rauth, this is what I do...
digital7 = OAuth1Session(client_key=MY_KEY, client_secret=MY_SECRET)
url = '
http://previews.7digital.com/clip/1940593'
resp = digital7.get(url) # I expect 'resp' to contain the preview
print resp.status_code
print resp.text
... and my output is
401
Error: Authorization failed for method <GET> and URL <
http://previews.7digital.com/clip/1940593>. Missing oauth_consumer_key
In the case of requests-oauthlib, this is what I do...
digital7 = rauth.OAuth1Service(
name='7digital',
consumer_key=MY_KEY,
consumer_secret=MY_SECRET,
request_token_url='
https://api.7digital.com/1.2/oauth/requesttoken',
access_token_url='
https://api.7digital.com/1.2/oauth/accesstoken',
authorize_url='
https://api.7digital.com/1.2/oauth/authorize',
base_url='
https://api.7digital.com/1.2/')
request_token, request_token_secret = digital7.get_request_token()
... and I get the following XML response
<?xml version="1.0" encoding="utf-8"?><response xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" status="ok" version="1.2" xsi:noNamespaceSchemaLocation="
http://api.7digital.com/1.2/static/7digitalAPI.xsd"><oauth_request_token><oauth_token>C7XGYVV</oauth_token><oauth_token_secret>HZgdt8ii/0CHCgYQ8szQtA==</oauth_token_secret></oauth_request_token></response>
I can see that it contains oauth_token and oauth_token_secret. I don't know how to use them. I tried generating the request as follows
http://previews.7digital.com/clip/1940593?oauth_token=C7XGYVV&oauth_token_secret=HZgdt8ii/0CHCgYQ8szQtA==&oauth_consumer_key=MY_KEYbut it says
Error: Authorization failed for method <GET> and URL <
http://previews.7digital.com/clip/1940593?oauth_token=C7XGYVV&oauth_token_secret=HZgdt8ii/0CHCgYQ8szQtA==&oauth_consumer_key=MY_KEY>.
Missing OAuth signatureNow where can get OAuth signature (and other required fields) from?
I spent hours going through examples from other APIs, the OAuth website, etc. but I could not get even one lousy preview in the end. And I have no idea if what I've done until now is even correct. I'll be very grateful if someone can tell me how to get a song preview with the API.
Thanks!