Search code examples
phpapitumblr

How to obtain a tumblr post ID after creating it with Tumblr PHP API?


If I have setup a script to post a blog post to Tumblr using their API.

$client->createPost($blog->name, array(
                        'type' => 'link',
                        'tags' => '',
                        'title' => $post->title,
                        'description' => $body[0],
                        'url' => site_url($post->blog_slug),
                        'thumbnail' => base_url() . $post->preview_image
                    )
                );

Does anyone know how I can obtain the ID of this post that has been newly created? AFAIK the documentation doesn't say anything about obtaining the ID of the post after creating it.


Solution

  • You can use the id attribute of response returned by createPost method.

    $response = $client->createPost($blog->name, array(
                        'type' => 'link',
                        'tags' => '',
                        'title' => $post->title,
                        'description' => $body[0],
                        'url' => site_url($post->blog_slug),
                        'thumbnail' => base_url() . $post->preview_image
                    )
                );
    $postURL = 'https://'.$blog->name.'tumblr.com/post/'.$repsonse->id;