Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
Never
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build

# OAuth 2.0 kimlik doğrulama bilgileri
CLIENT_ID = 'your_client_id'
CLIENT_SECRET = 'your_client_secret'
REFRESH_TOKEN = 'your_refresh_token'

# Blog ID ve API anahtarları
BLOG_ID = 'your_blog_id'
API_KEY = 'your_api_key'

# Kimlik doğrulama bilgilerini kullanarak bir erişim belirteci oluşturun
creds = Credentials.from_authorized_user_info(info=None,
                    client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
                    refresh_token=REFRESH_TOKEN)

# Blogspot API'sini oluşturun
service = build('blogger', 'v3', credentials=creds)

# Yeni bir gönderi oluşturma
post_data = {
    "kind": "blogger#post",
    "blog": {
        "id": BLOG_ID
    },
    "title": "New Post Title",
    "content": "New post content"
}
service.posts().insert(blogId=BLOG_ID, body=post_data).execute()

# Mevcut gönderileri listeleme
posts = service.posts().list(blogId=BLOG_ID, maxResults=10, key=API_KEY).execute()
for post in posts["items"]:
    print(post["title"])