tumblr / docs

Tumblr's public platform documentation.
Apache License 2.0
109 stars 27 forks source link

Is there a version of Tumblr API Client that supports NPF(Neue Posting Format)?(PHP) #73

Closed asker26 closed 2 years ago

asker26 commented 2 years ago

Hi there, I actually posted my question on Official Tumblr API Client for PHP as well, but since that place seemed quite inactive for a long time, I'm concerned that someone will reply to me there, so I'll try my luck here hoping someone will help me( 3 days ago I asked a question here and you responded and solved the issue so quick, thank you so much for that too). So, I'm using official Client to share my posts via API and what I'm trying is to change to NPF from Legacy posting format on Tumblr API, I didn't have much trouble on doing so with text, image, link and almost any other types. However, I couldn't manage to convert video type from legacy to NPF. I guess there's too much difference? In legacy we directly sent video data(contents), but I couldn't find that parameter on new format. Instead, you need to give an URL of video, which really works on some videos( such as YouTube videos or the videos hosted by Tumblr itself). But if I want to share a video from my site, It'll only share the URL similar to Link format. Here's what I was sending to old format(Which works fine): $sendData[ 'type' ] = 'video'; $sendData[ 'data' ] = $video; $sendData[ 'caption' ] = $message; And these two data formats for NPF: $sendData[ 'content' ][] = [ 'type' => 'video', 'media'=> [ 'type' => 'video/mp4', 'url'=> $video, 'height'=> 640, 'width' => 480, 'hd' => false ] ]; OR $sendData[ 'content' ][] = [ 'type' => 'video', 'url'=> $video, ]; Please note that both codes works fine if it's a YouTube or Tumblr video : https://i.imgur.com/mngUn7F.png But if I were to try it with any other video link: https://i.imgur.com/50RCtqA.png This is the video URL I fail to post correctly: https://dev0.hex.az/wp-content/uploads/2022/01/videoplayback.mp4 .

Maybe I didn't understand the documentation well, but after two days of investigation I've come to a dead end. Any help is much appreciated!

nightpool commented 2 years ago

Hi @Askerased, it sounds like your issue combines two questions, one about Tumblr official API clients, and one about uploading media. I can't answer anything about the API Clients, since I don't work for Tumblr, but as far as uploading media goes, you can find a description of how to do so in the "User Uploaded Media" section of the API documentation: https://www.tumblr.com/docs/en/api/v2#:~:text=in%20your%20post.-,User%20Uploaded%20Media,-In%20order%20to

In order to support user uploaded media (photos, videos, etc.), the creation and edit routes also support a multi-part form request where the first part contains the JSON body and subsequent parts contain media data. The Content-Type: multipart/form-data header must be used in this case.

To specify which media data pertains to which block, we use a unique identifier in the JSON body and this identifier is used as the key in the form data.

So instead of using a URL, your JSON data will use an identifier, like this:

{
    "content": [
        {
            "type": "image",
            "media": [
                {
                    "type": "image/jpeg",
                    "identifier": "some-identifier",
                    "width": 250,
                    "height": 200
                }
            ]
        }
    ]
}

And your request itself will look like this:

--TumblrBoundary
Content-Disposition: form-data; name="json"
Content-Type: application/json

{JSON encoded parameters}
--TumblrBoundary
Content-Disposition: form-data; name="some-identifier"; filename="filename.jpg"
Content-Type: image/jpeg

{image data}
--TumblrBoundary--

With the JSON in the first slot, and the image/video data in the second slot.

This works for both image and video uploads

cyle commented 2 years ago

☝️ nightpool is correct, re: media upload handling. Please let us know if that doesn't help!

As for "official" NPF support in our client libraries (like the PHP one), it's certainly something we would like to include, but that work has not gotten priority on our roadmap as of yet, so I can't provide an ETA. I'll pass this request along though, thank you for the feedback!