-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Choonho Son <[email protected]>
- Loading branch information
Choonho Son
committed
Oct 31, 2023
1 parent
138be84
commit da99a08
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ authors = [ | |
] | ||
|
||
dependencies = [ | ||
'requests' | ||
'requests', | ||
'google-api-python-client' | ||
] | ||
|
||
[build-system] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
from google_auth_oauthlib.flow import InstalledAppFlow | ||
from googleapiclient.discovery import build | ||
|
||
# 구글 클라우드 콘솔에서 받은 자격 증명 파일 경로 | ||
CLIENT_SECRETS_FILE = 'credentials.json' | ||
|
||
# Blogger API 서비스 이름 | ||
API_SERVICE_NAME = 'blogger' | ||
API_VERSION = 'v3' | ||
|
||
# 인증 범위 | ||
SCOPES = ['https://www.googleapis.com/auth/blogger'] | ||
|
||
blog_id = os.environ.get("BLOGSPOT_ID") | ||
|
||
def create_blogger_post(title, content): | ||
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES) | ||
credentials = flow.run_local_server(port=0) | ||
|
||
service = build(API_SERVICE_NAME, API_VERSION, credentials=credentials) | ||
|
||
blog_id = blog_id # 포스트를 게시할 블로그 ID | ||
body = { | ||
'kind': 'blogger#post', | ||
'title': title, | ||
'content': content, | ||
} | ||
|
||
posts = service.posts() | ||
request = posts.insert(blogId=blog_id, body=body) | ||
response = request.execute() | ||
print('포스트가 성공적으로 생성되었습니다. 포스트 ID: %s' % response['id']) | ||
|
||
if __name__ == '__main__': | ||
create_blogger_post('새로운 포스트 제목', '새로운 포스트 내용') |