cjrasmussen / BlueskyApi

Simple helper for interacting with the Bluesky API/AT protocol
MIT License
27 stars 5 forks source link

Can I POST 4 images using this library? #5

Closed e1blue closed 10 months ago

e1blue commented 11 months ago

Can I POST 4 images using this library?

cjrasmussen commented 11 months ago

I haven't tested it but you should be able to do something like the following for multiple images (I was lazy and only did two):


$response = $bluesky->request('POST', 'com.atproto.repo.uploadBlob', [], $image_file_content1, 'image/png');
$image1 = $response->blob;

$response = $bluesky->request('POST', 'com.atproto.repo.uploadBlob', [], $image_file_content2, 'image/png');
$image2 = $response->blob;

$args = [
    'collection' => 'app.bsky.feed.post',
    'repo' => $bluesky->getAccountDid(),
    'record' => [
        'text' => 'Testing with two images #TestingInProduction',
        'langs' => ['en'],
        'createdAt' => date('c'),
        '$type' => 'app.bsky.feed.post',
        'embed' => [
            '$type' => 'app.bsky.embed.images',
            'images' => [
                [
                    'alt' => 'A test image',
                    'image' => $image1,
                ],
                [
                    'alt' => 'A second test image',
                    'image' => $image2,
                ],
            ],
        ],
    ],
];
$response = $bluesky->request('POST', 'com.atproto.repo.createRecord', $args);```
e1blue commented 10 months ago

I tried it, but I got Refresh Token Authentication Error: Syntax error. I'll think about it a little more myself. Thank you for your answer

e1blue commented 10 months ago

I commented out $refresh_token = $bluesky->getRefreshToken(); etc. and was able to successfully submit multiple images. Thank you very much. It was very helpful.

cjrasmussen commented 10 months ago

I'm curious to see the code you were using to get the Refresh Token Authentication Error, as I've been unable to reproduce that. That said, if you're doing a single post of four images at an infrequent rate, you should be safe not using the refresh token.

e1blue commented 10 months ago

Thank you for your confirmation & reply. It was very helpful.