EzDevInfo.com

pytumblr

A Python Tumblr API v2 Client

How to add meta tags to Tumblr API's blog header?

The Tumblr API is really impressive as it allows me to publish directly into the blog. However I would like to add meta for Twitter card as well. Is there any way to achieve this?

       client = pytumblr.TumblrRestClient(
            app.config['CONSUMER_KEY'],
            app.config['CONSUMER_SECRET'],
            app.config['OAUTH_TOKEN'],
            app.config['OAUTH_SECRET'],
        )
        if news.is_published:
            body = ''
            if news.image_url_list and len(news.image_url_list) > 0:
                body = '<img src="{0}" /><br/>'.format(news.image_url_list[0])
            slug = Slugify.slugify(news.head_line)
            post = client.create_text("xxx.tumblr.com",
                                      state="published",
                                      tags=news.tag_list,
                                      format='html',
                                      slug=slug,
                                      title=news.head_line,
                                      body=body + news.summary.encode('utf-8'))

How do I add these meta tags to the blog post?

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@flickr" />
<meta name="twitter:title" content=? news.head_line ? />
<meta name="twitter:description" content=? news.description ? />
<meta name="twitter:image" content=? news.image_url_list[0] ? />

Source: (StackOverflow)

How to add a custom tweet to Tumblr API?

I have the following code to post a blog on Tumblr through Tumblr API.

 post = client.create_text("xxx.tumblr.com",
                                      state="published",
                                      tags=utag_list,
                                      format='html',
                                      tweet=tweet.encode('utf-8'),
                                      slug=sluged_header,
                                      title=news.head_line.encode('utf-8'),
                                      body=body)

Strangely the tweet parameter doesnt do anything.

Looking at my blog source, I can see:

<li><a rel='nofollow' href="https://twitter.com/intent/tweet?text=Teenagers%20rescue%20elderly%20couple%20from%20sinking%20after%20car%20crashes%20into%20lake%20-%20Teenage%20wind-surfing...%20http%3A%2F%2Ftmblr.co%2FZ_F3uj1qlCL9u" class="share-item twitter" target="_blank">Tweet</a></li>

This is the default tweet message generated. Somehow my custom tweet message is completely ignored. And not generated in source. Hence the tweet sharing doesn't see the custom message. Any advice please?


Source: (StackOverflow)

Advertisements