2
import time
import giphy_client
from giphy_client.rest import ApiException
from pprint import pprint

# create an instance of the API class
api_instance = giphy_client.DefaultApi()
api_key = 'dc6zaTOxFJmzC' # str | Giphy API Key.
q = 'cheeseburgers' # str | Search query term or prhase.
limit = 1 # int | The maximum number of records to return. (optional) (default to 25)
offset = 0 # int | An optional results offset. Defaults to 0. (optional) (default to 0)
rating = 'g' # str | Filters results by specified rating. (optional)
lang = 'en' # str | Specify default country for regional content; use a 2-letter ISO 639-1 country code. See list of supported languages <a href = \"../language-support\">here</a>. (optional)
fmt = 'json' # str | Used to indicate the expected response format. Default is Json. (optional) (default to json)

try: 
    # Search Endpoint
    api_response = api_instance.gifs_search_get(api_key, q, limit=limit, offset=offset, lang=lang, fmt=fmt)
    #pprint(api_response)
except ApiException as e:
    print("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)

api_response['data']

Hello, I cant figure out how to convert api_response, which is a inline response, to something that I can manipulate such as a python dictionary. I need to figure out a way to save or convert it. I can only print it atm.

Thanks!

enter image description here

BillyRay
  • 413
  • 2
  • 10
  • 24

2 Answers2

4

I figured out a way to extract the data

x = api_response.data
y = x[0]
y.images.downsized.url

Not sure if its the best method but it works for me!

BillyRay
  • 413
  • 2
  • 10
  • 24
0

I came here as I see this using a swagger auto generated client.

https://editor.swagger.io/

Fixed with .to_dict() which may also work here.

user3712978
  • 167
  • 2
  • 6