Reputation: 6031
I am trying to use Tumblr API to post something to my secondary blog. I am using Tumblpy Python package because official Tumblr client is for Python 2 only and it seems abandoned anyway.
I authorized the app and I took a look at Tumblr console where I picked up all the keys from. I started to play around with it and I have noticed that I can successfully post to my primary blog, but not on secondary (getting {TumblpyError} 404 'There was an error making your request.'
error all the time).
This is the code I've been trying out:
from tumblpy import Tumblpy
def post_tumblr(
url,
comment='',
tags='',
**kwargs
):
t = Tumblpy(
APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
)
blog_url = t.post('user/info')
blog_url = blog_url['user']['blogs'][0]['url'] # POSTING TO PRIMARY BLOG WORKS
# blog_url = blog_url['user']['blogs'][1]['url'] # CANNOT POST TO SECONDARY BLOG?
post_url = t.post(
'post',
blog_url=blog_url,
params={
'type': 'video',
'embed': url,
'caption': comment,
'tags': tags,
}
)
return True
Is there some catch in posting to secondary blog in Tumblr API?
Upvotes: 1
Views: 240
Reputation: 4852
This is an interesting one. The first thing to note is that in the Tumblr API, any blog.url
is a full url, including the scheme: http://
or https://
. However, in any /blog/{blog-identifier}/*
API request, it does not accept a full url, only the hostname: example.com
or demo.tumblr.com
.
Given this information, it seems like neither of your requests should work, so I checked out the code for Tumblpy a bit. It turns out that Tumblpy does accept a full url for a {blog-identifier}
, by stripping away everything except the hostname. However, it only works with http://
urls, and not https://
urls, as seen here.
If you have a blog with SSL enabled, the url
field will be an https://
link, and then Tumblpy will not handle it correctly. I'm assuming this is the case for your secondary blog; you can check on your settings page for that blog.
Assuming this is the case, the best fix will be to just construct the hostname yourself before calling Tumblpy.post()
. Just use user.blogs[i].name + ".tumblr.com"
. Or, you can parse the hostname from the url too. Either approach will work.
Upvotes: 1