Giphy / giphy-android-sdk

Home of the GIPHY SDK Android example app, along with Android SDK documentation, issue tracking, & release notes.
https://developers.giphy.com/
Mozilla Public License 2.0
91 stars 40 forks source link

[Question] How to retrieve the right media url by id #191

Closed Nico3652 closed 1 year ago

Nico3652 commented 1 year ago

I've created a Flutter app so my widgets are rendered on the flutter side. So I have to retrieve the media url in order to display it inside my Image.network() widget. The problem is not on the Flutter side.

This use case is in a messaging part in my app : -> A user pick/tap a media in the android grid -> then I'm saving in database the media ID retrieved -> and then when the chat UI is loaded I'm getting the media url by ID to load the Gif in my image widget

Nothing special until now everything is ok, but from this next method the result.data is not returning the right url I need

fun getMediaUrlById(id: String, completion: (result: String?) -> Unit) {
        GPHCore.gifById(id) { result, e ->
            completion(result?.data?.url)
            //completion(result?.data?.contentUrl)
            //completion(result?.data?.bitlyGifUrl)
            //completion(result?.data?.videoUrl)
            //completion(result?.data?.bitlyUrl)
            //completion(result?.data?.sourcePostUrl)
            //completion(result?.data?.source)
            e?.let { error ->
                Log.e("Error while retrieving media url" , error.toString())
            }
        }
    }

Here is the same method in Swift on the iOS SDK :

func getMediaUrl(id: String, completion: ((String?) -> Void)? = nil) {
        GiphyCore.shared.gifByID(id) { (response, error) in
            if let media = response?.data {
                DispatchQueue.main.sync { [weak self] in
                    let url = media.url(rendition: .fixedWidth, fileType: .gif)
                    completion?(url)
                }
            }
            else {
                completion?(nil)
            }
        }
    }

For the same GIF : (Do right click + open new tab on the link)

On the iOS side, the url retrieved is : https://media0.giphy.com/media/iIk7rXWg3dL894tIg9/200w.gif?cid=69172d4b342ce44e7214c335b72edc565f933fc066d6cf54&rid=200w.gif&ct=ts (the media itself)

Whereas on Android side :
https://giphy.com/stickers/laugh-hehe-gebyk-iIk7rXWg3dL894tIg9 (the website + media)

I tried all these but the result is the same or null/empty

completion(result?.data?.url)
completion(result?.data?.contentUrl)
completion(result?.data?.bitlyGifUrl)
completion(result?.data?.videoUrl)
completion(result?.data?.bitlyUrl)
completion(result?.data?.sourcePostUrl)
completion(result?.data?.source)

I searched for doc and inside classes like Media() class but no details found for now

Is there a way to retrieve from the data the same url that provide iOS SDK ?

Thanks for any help on this!

ALexanderLonsky commented 1 year ago

Hi @Nico3652, Usually, you access a needed rendition in this way: result?.data?.images.fixedWidth.gifUrl

Here you can read more about the renditions.

In Android SDK we also have a convenience function to take a needed rendition: result?.data?.imageWithRenditionType(RenditionType.fixedWidth).gifUrl

We use it internally, but it's exposed to the public too.

Nico3652 commented 1 year ago

Hi @ALexanderLonsky

Thanks a lot for answer this is what I was looking for !