Blueskyやーる

# はじめに

BlueskyでAPIたたけるみたいなのでやってみました
https://bsky.app/profile/gachimoto3.bsky.social

# 開発環境
- Windows 11
- Python 3.10

# ログイン

identifier、passwordを入力してください。

```python
import requests
import json

url = "https://bsky.social/xrpc/com.atproto.server.createSession"

data = {
    "identifier": "gachimoto3.bsky.social",
    "password": ""
}

headers = {
    "Content-Type": "application/json; charset=UTF-8"
}

response = requests.post(url, data=json.dumps(data), headers=headers)
print(response)

accessJwt = response.json()["accessJwt"]
print(accessJwt) 

did = response.json()["did"]
print(did) 
```

accessJwtとdidを用います。


# 投稿を取得

actorに取得したい投稿のidentifierを入力してください。
accessJwtはログイン時に取得したものを用います。

```csharp
import requests
import json
url = "https://bsky.social/xrpc/app.bsky.feed.getAuthorFeed"
params = {
    "actor": "gachimoto3.bsky.social",
    "limit": 10
}

accessJwt = ""

headers = {
    "Authorization": f"Bearer {accessJwt}"
}

response = requests.get(url, params=params, headers=headers)
responseJSON = response.json()

for feed in responseJSON["feed"]:
    print(feed["post"]["record"]["text"])
    if "embed" in feed["post"]:
        print(feed["post"]["embed"]["images"][0]["fullsize"])

# # レスポンスデータをdata.jsonファイルに保存
# with open("data.json", "w") as file:
#     json.dump(responseJSON, file)
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/e0315e37-e4da-8bce-24d9-c893ecb4050e.png)

https://nigauri.me/tech/bluesky/authorfeed2rss-using-gas/

# 投稿する

accessJwtとdidはログイン時に取得したものを用います。

```python
import requests
import json
from datetime import datetime

url = "https://bsky.social/xrpc/com.atproto.repo.createRecord"

accessJwt = ""
did = ""

data = {
    "repo": did,
    "collection": "app.bsky.feed.post",
    "record": {
        "text": "Pythonから投稿できたよ",
        "createdAt": datetime.now().isoformat()
    }
}

headers = {
    "Authorization": f"Bearer {accessJwt}",
    "Content-Type": "application/json; charset=UTF-8"
}

response = requests.post(url, json=data, headers=headers)
responseJSON = response.json()
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/63863/20a6bc84-7bd0-7b0b-4283-74eb958cdc14.png)

https://nigauri.me/tech/bluesky/post-to-bluesky-using-gas/

# API一覧

一覧をやっていくといろいろできそうです！

```
com.atproto.admin.defs
com.atproto.admin.disableAccountInvites
com.atproto.admin.disableInviteCodes
com.atproto.admin.enableAccountInvites
com.atproto.admin.getInviteCodes
com.atproto.admin.getModerationAction
com.atproto.admin.getModerationActions
com.atproto.admin.getModerationReport
com.atproto.admin.getModerationReports
com.atproto.admin.getRecord
com.atproto.admin.getRepo
com.atproto.admin.resolveModerationReports
com.atproto.admin.reverseModerationAction
com.atproto.admin.searchRepos
com.atproto.admin.takeModerationAction
com.atproto.admin.updateAccountEmail
com.atproto.admin.updateAccountHandle
com.atproto.identity.resolveHandle
com.atproto.identity.updateHandle
com.atproto.repo.applyWrites
* com.atproto.repo.createRecord
com.atproto.repo.deleteRecord
com.atproto.repo.describeRepo
com.atproto.repo.getRecord
com.atproto.repo.listRecords
com.atproto.repo.putRecord
com.atproto.repo.rebaseRepo
com.atproto.repo.strongRef
com.atproto.repo.uploadBlob
com.atproto.moderation.createReport
com.atproto.moderation.defs
com.atproto.label.defs
com.atproto.label.queryLabels
com.atproto.label.subscribeLabels
com.atproto.server.createAccount
com.atproto.server.createAppPassword
com.atproto.server.createInviteCode
com.atproto.server.createInviteCodes
* com.atproto.server.createSession
com.atproto.server.defs
com.atproto.server.deleteAccount
com.atproto.server.deleteSession
com.atproto.server.describeServer
com.atproto.server.getAccountInviteCodes
com.atproto.server.getSession
com.atproto.server.listAppPasswords
com.atproto.server.refreshSession
com.atproto.server.requestAccountDelete
com.atproto.server.requestPasswordReset
com.atproto.server.resetPassword
com.atproto.server.revokeAppPassword
com.atproto.sync.getBlob
com.atproto.sync.getBlocks
com.atproto.sync.getCheckout
com.atproto.sync.getCommitPath
com.atproto.sync.getHead
com.atproto.sync.getRecord
com.atproto.sync.getRepo
com.atproto.sync.listBlobs
com.atproto.sync.listRepos
com.atproto.sync.notifyOfUpdate
com.atproto.sync.requestCrawl
com.atproto.sync.subscribeRepos
app.bsky.actor.defs
app.bsky.actor.getProfile
app.bsky.actor.getProfiles
app.bsky.actor.getSuggestions
app.bsky.actor.profile
app.bsky.actor.searchActors
app.bsky.actor.searchActorsTypeahead
app.bsky.embed.external
app.bsky.embed.images
app.bsky.embed.record
app.bsky.embed.recordWithMedia
app.bsky.feed.defs
* app.bsky.feed.getAuthorFeed
app.bsky.feed.getLikes
app.bsky.feed.getPostThread
app.bsky.feed.getPosts
app.bsky.feed.getRepostedBy
app.bsky.feed.getTimeline
app.bsky.feed.like
app.bsky.feed.post
app.bsky.feed.repost
app.bsky.graph.block
app.bsky.graph.follow
app.bsky.graph.getBlocks
app.bsky.graph.getFollowers
app.bsky.graph.getFollows
app.bsky.graph.getMutes
app.bsky.graph.muteActor
app.bsky.graph.unmuteActor
app.bsky.notification.getUnreadCount
app.bsky.notification.listNotifications
app.bsky.notification.updateSeen
app.bsky.richtext.facet
app.bsky.unspecced.getPopular
```

https://qiita.com/gpsnmeajp/items/eb665d639f088b85454e

お疲れさまでした。