Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonでQiita APIを叩いて新規投稿するスクリプトの例 (最小構成的な) #536

Open
YumaInaura opened this issue Jan 31, 2019 · 0 comments

Comments

@YumaInaura
Copy link
Owner

PythonでQiita APIを叩いて新規投稿するスクリプトの例 (最小構成的な)

Ref

Qiita API を利用して記事を投稿する - Qiita

Script

import requests
import os

if __name__ == "__main__":
    item = {
        'title': 'title',
        "coediting": False,
        'tags': [
          {
            "name": "Python",
            "versions": ["0.0.1"]
          }
        ],
        'private': True,
        'tweet': False,
    }

    item['body'] = 'ABC'


    url = 'https://qiita.com/api/v2/items'

    token = os.environ['TOKEN']

    headers = {
     'Authorization': 'Bearer {}'.format(token),
     'Content-Type': 'application/json',
    }

    print(item)
    print(headers)

    res = requests.post(url, headers=headers, json=item)
    print(res.json())

Execute

TOKEN=XXXXXXXXXXXXXXXXXXXXX python qiita.py

結果

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant