通过python了解Blogger API的基本知识

时间:2019-04-30 23:24:46

标签: python blogger google-api-client

我正在尝试使用Blogger API。这些文档尚不清楚,我非常无法理解如何在Blogger上发布内容。

我遇到了以下代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

from __future__ import print_function

import sys

from oauth2client import client
from googleapiclient import sample_tools

def main(argv):
    # Authenticate and construct service.
    service, flags = sample_tools.init(
        argv, 'blogger', 'v3', __doc__, __file__,
        scope='https://www.googleapis.com/auth/blogger')

    try:
        users = service.users()

        # Retrieve this user's profile information
        thisuser = users.get(userId='self').execute()

        blogs = service.blogs()

        # Retrieve the list of Blogs this user has write privileges on
        thisusersblogs = blogs.listByUser(userId='self').execute()

        posts = service.posts()

        blog = thisusersblogs['items'][0]
        body = {
        "kind": "blogger#post",
        "id": "ID-NUMBER",
        "title": "posted via python",
        "content":"<div>hello world test</div>"
        }
        if blog['id'] == '*** my_blog_id ***':
            posts.insert(blogId=blog['id'], body='test post', isDraft=True).execute()

    except client.AccessTokenRefreshError:
        print ('The credentials have been revoked or expired, please re-run'
               'the application to re-authorize')

if __name__ == '__main__':
    main(sys.argv)

但是我不明白我需要在哪里插入哪些信息才能使其正常工作。我唯一理解的是我需要插入ID号"id": "ID-NUMBER"(进入Blogger时从URL中获取)。但是我不明白我需要通过args传递给脚本什么。从文档中我了解到我需要传递your_client_id your_client_secret,但是我似乎无法理解这两个值/对象/文件的确切含义。我还需要插入什么其他信息?代替__doc__, __file__,应该是什么?

0 个答案:

没有答案