Upgrade to Pro — share decks privately, control downloads, hide ads and more …

速習XRPC / Learning XRPC

鎌倉
April 28, 2023

速習XRPC / Learning XRPC

Bluesky/ATProtocol勉強会 #1の発表資料です。
Bluesky (ATP) のAPIを叩いてみたい人向けに、基本的な概念や触り方を解説しています。

鎌倉

April 28, 2023
Tweet

More Decks by 鎌倉

Other Decks in Technology

Transcript

  1. લఏ஌ࣝͱΰʔϧ w લఏ஌ࣝ w Ұൠతͳ8FC"1*͕৮ΕΔ w ˞࣮૷ऀࢹ఺ͷ࿩͕த৺Ͱ͢ w ΰʔϧ w

    -FYJDPOͷجຊతͳา͖ํ͕Θ͔Δ w ཁ఺Λ͔͍ͭ·ΜͰۦ͚଍ؾຯʹਐΈ·͢
  2. 931$ w $SPTTTZTUFN3FNPUF1SPDFEVSF$BMMT w 31$ ԕִखଓ͖ݺͼग़͠ ͷن֨ͷҰछ w H31$ 40"1

     w "51SPUPDPMͷಠࣗ࢓༷ w )551 4 ͷ্Ͱಈ࡞ w 1%4ͱͷσʔλͷ΍ΓऔΓʹར༻
  3. -FYJDPOͷܕ w PCKFDU w QSPDFEVSF w RVFSZ w ϓϦϛςΟϒܕ JOUFHFS΍TUSJOHͳͲ

     w ಛघͳܕ SFDPSE SFG VOJPO CMPC UPLFO TVCTDSJQUJPOͳͲ  w ࠓճ͸SFDPSEͷΈѻ͍·͢
  4. PCKFDU { "id": "app.bsky.actor.defs", "defs": { "profileViewBasic": { "type": "object",

    "required": ["did", "handle"], "properties": { "did": { "type": "string" }, "handle": { "type": "string" }, "avatar": { "type": "string" }, "viewer": { "type": "ref" }, "labels": { "type": "array" } } } } } w Ұൠతͳσʔλܕ w SFRVJSFE͸OPUOVMM w ˠͷ/4*%͸ BQQCTLZBDUPSEFGTQSP fi MF7JFX#BTJD ˞ൈਮ
  5. QSPDFEVSF { "id": "com.atproto.server.createSession", "defs": { "main": { "type": "procedure",

    "input": { "schema": { "properties": { "identifier": { "type": "string" }, "password": { "type": "string" } } } }, "output": { "schema": { "properties": { "accessJwt": { "type": "string" }, "did": { "type": "string" }, } } } } } } w ߋ৽ܥϝιου w JOQVUPVUQVUΛ࣋ͭ w ӈͷ/4*%͸ DPNBUQSPUPTFSWFSDSFB UF4FTTJPO NBJO͸লུ ˞ൈਮ
  6. RVFSZ { "id": "app.bsky.feed.getTimeline", "defs": { "main": { "type": "query",

    "parameters": { "type": "params", "properties": { "cursor": { "type": "string" } } }, "output": { "schema": { "properties": { "cursor": { "type": "string" }, "feed": { "type": "array" } } } } } } } w ࢀরܥϝιου w QBSBNFUFSTPVUQVUΛ࣋ͭ w ˠͷ/4*%͸ BQQCTLZGFFEHFU5JNFMJO F ˞ൈਮ
  7. ϩάΠϯͷ-FYJDPO { "id": "com.atproto.server.createSession", "defs": { "main": { "type": "procedure",

    "input": { "encoding": "application/json", "schema": { "required": [ "identifier", "password" ], "properties": { "identifier": { "type": "string" }, "password": { "type": "string" } } } } } } } ˞ൈਮ ϦΫΤετ͸1045 ϦΫΤετ#PEZ͸+40/ JEFOUJ fi FSͱQBTTXPSE͸ඞਢ IBOEMFPSFNBJM ΤϯυϙΠϯτ͸ YSQDDPNBUQSPUPTFSWFSDSFBUF4FTTJPO
  8. ϩάΠϯͷϦΫΤετ curl -X POST \ -H 'Content-Type: application/json' \ -d

    '{"identifier": "tester.bsky.social", "password": "foo"}' \ 'https://bsky.social/xrpc/com.atproto.server.createSession' # response { "did":"did:plc:ji4f2ypncqko5cm62pmyxh67", ... "accessJwt":"...", "refreshJwt":"..." } ೝূ͕ඞཁͳΤϯυϙΠϯτ͸ ฦ͖ͬͯͨ+85ΛϦΫΤετʹؚΊΔ
  9. RVFSZͷ-FYJDPO ϢʔβϑΟʔυͷऔಘ { "id": "app.bsky.feed.getAuthorFeed", "defs": { "main": { "type":

    "query", "parameters": { "type": "params", "required": ["actor"], "properties": { "cursor": { "type": "string" } } } } } } ˞ൈਮ ϦΫΤετ͸(&5 ΫΤϦύϥϝʔλ ΤϯυϙΠϯτ͸ YSQDBQQCTLZGFFEHFU"VUIPS'FFE BDUPS ͲͷϢʔβ͔ ͸ඞਢ
  10. ϦϙδτϦ %BUB3FQPTJUPSZ w 5-%3 w ϦϙδτϦ͸ॺ໊σʔλͷίϨΫγϣϯ w HJUͷϦϙδτϦΈ͍ͨͳ΋ͷ ͨͩ͠%#ͷϨίʔυ༻ 

    w Ϣʔβ͸֤ʑͷެ։ΞΫςΟϏςΟΛࣗ෼ͷϦϙδτϦʹ௥ه w #MVFTLZ BQQCTLZ ͷ৔߹ɺ౤ߘɾϑΥϩʔɾ͍͍ͶͳͲ͕֨ೲ͞ ΕΔ
  11. SFDPSE { "id": "app.bsky.feed.post", "defs": { "main": { "type": "record",

    "key": "tid", "record": { "type": "object", "required": ["text", "createdAt"], "properties": { "text": { "type": "string" }, "createdAt": { "type": "string", "format": "datetime" } } } } } } w ϦϙδτϦ༻ͷσʔλܕ w ˠ͸#MVFTLZͷ౤ߘ QPTU ͷܕ ˞ൈਮ
  12. ϦϙδτϦૢ࡞ { "id": "com.atproto.repo.createRecord", "defs": { "main": { "type": "procedure",

    "input": { "encoding": "application/json", "schema": { "type": "object", "properties": { "repo": { "type": "string" }, "collection": { "type": "string" }, "record": { "type": "unknown" } } } } } } } w ϦϙδτϦ΁ͷϨίʔυ ௥ՃͷQSPDFEVSF w ౤ߘ΍ϑΥϩʔͳͲ͸ର ৅ͱͳΔSFDPSEΛ౉ͯ͠ ߦ͏ ˞ൈਮ
  13. ౤ߘ࡞੒ͷϦΫΤετ curl -X POST \ -H 'Authorization: Bearer ${accessJwt}' \

    -H 'Content-Type: application/json' \ -d '{ "repo": "tester.bsky.social", "collection": "app.bsky.feed.post", "record": { "text": "Hello, world!", "createdAt": "2023-04-28T22:00:00+09:00" } }' \ 'https://bsky.social/xrpc/com.atproto.repo.createRecord'