Goodreads Developers discussion

27 views
questions > Unable to query for author. What am I missing?

Comments Showing 1-1 of 1 (1 new)    post a comment »
dateUp arrow    newest »

message 1: by Normandantzig1 (new)

Normandantzig1 | 1 comments I am new to this.
I am having a problem writing a program to search for all of the books an author wrote. I am also unclear on what the session variables do and how to make them work. I assembled this from the API examples.

#Environment Variables and Imports
from rauth import OAuth1Service

try:
read_input = raw_input
except NameError:
read_input = input






#Security Stuff

goodreads = OAuth1Service(
name='goodreads',
consumer_key='********',
consumer_secret='*********',
request_token_url='https://www.goodreads.com/oauth/reque...',
authorize_url='https://www.goodreads.com/oauth/autho...',
access_token_url='https://www.goodreads.com/oauth/acces...',
base_url='https://www.goodreads.com/')


request_token, request_token_secret = goodreads.get_request_token(header_auth=True)
authorize_url = goodreads.get_authorize_url(request_token)
print( 'Visit this URL in your browser: ' + authorize_url)
accepted = 'n'
while accepted.lower() == 'n':
# you need to access the authorize_link via a browser,
# and proceed to manually authorize the consumer
accepted = read_input('Have you authorized me? (y/n) ')



session = goodreads.get_auth_session(request_token, request_token_secret)

# book_id 631932 is "The Greedy Python"
data = {'name': 'to-read', 'book_id': 631932}

# add this to our "to-read" shelf
response = session.post('https://www.goodreads.com/shelf/add_t...', data)


#---I don't know how to get these session variables to work. ----
# create a new session using only our consumer and access keys/secrets
# these values are what you need to save for subsequent access.
"""ACCESS_TOKEN = session.access_token
ACCESS_TOKEN_SECRET = session.access_token_secret

new_session = OAuth1Service(
consumer_key = CONSUMER_KEY,
consumer_secret = CONSUMER_SECRET,
access_token = ACCESS_TOKEN,
access_token_secret = ACCESS_TOKEN_SECRET,
)

# book_id 631932 is "The Greedy Python"
data = {'name': 'to-read', 'book_id': 631932}

# add this to our "to-read" shelf
response = new_session.post('https://www.goodreads.com/shelf/add_t...', data)

if response.status_code != 201:
raise StandardError('Cannot create resource: %s' % response.status_code)
else:
print('Book added!')
"""
#------I don't know how to get the search to work-----

search = goodreads.get_auth_session(request_token, request_token_secret)

data = {'q':"asimov", 'key':consumer_key}

search.authors('https://www.goodreads.com/search/inde...', data)


back to top