0

Code:

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

def giphyapi():
    api_instance = giphy_client.DefaultApi()
    api_key = '################################'
    tag = 'test'
    rating = 'pg-13'
    fmt = 'json'

    try:
        # Search Endpoint
        api_response = api_instance.gifs_random_get(api_key, tag = tag, rating = rating, fmt = fmt)
        ## here’s where I want to do stuff with the data
    except ApiException as exc:
        print("Exception when calling DefaultApi->gifs_random_get: %s\n" % exc)
    return None

giphyapi()

Hi! How do I convert api_instance into something manipulatable, such as a dict?
This is the same problem as this, but the solution that the question author found sadly did not work for me.

I have tried print(api_response.data[0].images.type), but that threw this error:
TypeError: 'RandomGif' object is not subscriptable

I also tried this:

for block in api_response["data"]:
    giftype = block["type"]

But that threw this error: TypeError: 'InlineResponse2002' object is not subscriptable

I’m using Python 3.8.1, and I’m also using giphy-python-client. Here is a list of RandomGif models. The one I’m trying to fetch in the two examples of what I tried above is type.

Any help is greatly appreciated!

zin
  • 11
  • 1

1 Answers1

0

I solved it thanks to shoot2thr1ll284 on Reddit.

You just use api_response.data.type and replace type with the property that you want to fetch.

zin
  • 11
  • 1