# -*- coding: utf-8 -*-
import ast
import json
import pprint
import requests
from oauth2client import tools
from try_auth import refresh_token
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
from api_imgur import upload_image
blogger_api_key = ""
blogger_id = ""
class Post:
@classmethod
def add(cls, header, title, content):
post_add_url = "https://www.googleapis.com/blogger/v3/blogs/{blogger_id}/posts".format(blogger_id=blogger_id)
data = json.dumps({"title": title, "content": content})
res = requests.post(post_add_url, params={"fields": ["id", "content", "title"], "title": "진짜 안녕", "key": blogger_api_key}, data=data, headers=header)
print(res.text)
def pre_task():
res = refresh_token()
access_token = ast.literal_eval(res.text)['access_token']
authorization_header = {"Authorization": "OAuth %s" % access_token,
'content-type': 'application/json'}
return authorization_header
def post(header, title, content):
# header = pre_task()
post_add_url = "https://www.googleapis.com/blogger/v3/blogs/{blogger_id}/posts".format(blogger_id=blogger_id)
data = json.dumps({"title": title, "content": content})
res = requests.post(post_add_url, params={"fields": ["id", "content", "title"], "key": blogger_api_key}, data=data, headers=header)
return res
2018년 5월 11일 금요일
Google API를 이용해서 Blog포스팅
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기