Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues creating a Bluesky post #15

Closed
matthewstreeter opened this issue Nov 11, 2024 · 53 comments
Closed

Issues creating a Bluesky post #15

matthewstreeter opened this issue Nov 11, 2024 · 53 comments
Assignees
Labels
bug Something isn't working

Comments

@matthewstreeter
Copy link

Hey Jeff! I reached out on Bluesky about this but I'm trying to get things setup with your module. I am having trouble getting the create post function to work for me however.

I'm able to from Get-BskyProfile, Get-BskyFollowers, etc. without an issue.

New-BskyPost_Error

@jdhitsolutions
Copy link
Owner

You need to specify the credential when you post, unless you set a PSDefaultParameterValue. Try again and include the -Credential parameter.

@matthewstreeter
Copy link
Author

matthewstreeter commented Nov 11, 2024

I do have my credential stored in PSDefaultParameterValues but I also get the same error message with the -Credential switch and stored secret creds.

Screenshot 2024-11-11 at 2 44 08 PM

@jdhitsolutions
Copy link
Owner

I see that now. You can run Get-BskyProfile and it returns your profile using the Credential stored in $PSDefaultParameterValues. That tells us the credential is good and configured properly. Can you run any of the other Get commands in the module?

@jdhitsolutions
Copy link
Owner

Let's confirm that you are running on a Windows platform.

@matthewstreeter
Copy link
Author

Seems like all of the Get-Bsky* commands work without issue

Screenshot 2024-11-11 at 2 55 10 PM

~~

I am actually on a Mac now. Is that the culprit?

@jdhitsolutions
Copy link
Owner

Ok. That's a good sign. I don't think the Mac should make a difference, but now I know I should at least test from Linux. Let's see if the information stream gives us any more data. Re-run the post command and add -InformationVariable iv

Assuming the command fails, run $iv.messagedata | format-list and paste the results.

@matthewstreeter
Copy link
Author

PS /Users/matthew/Documents/Scripting> $iv.MessageData | Format-List
{
"record": {
"$type": "app.bsky.feed.post",
"text": "Test posting to Bluesky via PSBluesky module from VSCode",
"createdAt": "2024-11-11T15:08:32.7856370-06:00"
},
"collection": "app.bsky.feed.post",
"repo": "matthewrstreeter.com"
}

Screenshot 2024-11-11 at 3 09 43 PM

@jdhitsolutions
Copy link
Owner

That is what I would expect to see up until the error. I'm assuming the repo value matches your credential username including casing.

The error message sounds like a DNS-type problem, but that doesn't make sense since the other commands work. I am puzzled and don't have an immediate solution. I'll have to think about how else to troubleshoot.

@matthewstreeter
Copy link
Author

Yes very odd but I was wondering if it might be DNS. My account is only a few days old.

Would using my non custom domain Bluesky username be something to try potentially?

@jdhitsolutions
Copy link
Owner

I'm using a custom domain name without issue. I was able to post from Linux. You've posted content so that shouldn't be an issue. Let's try another approach.

#use whatever variable name you are using for the credential object.
$repo = $cred.UserName
$pw = $cred.GetNetworkCredential().Password
$PDSHOST = 'https://bsky.social'
$headers = @{
    'Content-Type' = 'application/json'
}
$body = @{
    'identifier' = $user
    'password'   = $pw
} | ConvertTo-Json

$s = Invoke-RestMethod -Uri "$PDSHOST/xrpc/com.atproto.server.createSession" -Method Post -Headers $headers -Body $body
$token = $s.accessJwt
$headers = @{
    'Authorization' = "Bearer $token"
    'Content-Type'  = 'application/json'
}
$url = "$PDSHost/xrpc/com.atproto.repo.listRecords?repo=$repo&collection=app.bsky.feed.post&limit=5"
$r = Invoke-RestMethod -Uri $url -Method Get -Headers $headers

#this should return the last 5 posts
$r.records.value

Maybe this will validate the repo name.

@jdhitsolutions
Copy link
Owner

I don't think you finished setting up the verification for your custom name. https://bsky-debug.app/handle?handle=%40matthewrstreeter.com

@jdhitsolutions
Copy link
Owner

Never mind. I screwed that up.

@jdhitsolutions
Copy link
Owner

image

@jdhitsolutions
Copy link
Owner

Also run: (get-bskysession).diddoc and let's see what you get. It should look like

@context           : {https://www.w3.org/ns/did/v1, https://w3id.org/security/multikey/v1,
                     https://w3id.org/security/suites/secp256k1-2019/v1}
id                 : did:plc:ohgsqpfsbocaaxusxqlgfvd7
alsoKnownAs        : {at://jdhitsolutions.com}
verificationMethod : {@{id=did:plc:ohgsqpfsbocaaxusxqlgfvd7#atproto; type=Multikey;
                     controller=did:plc:ohgsqpfsbocaaxusxqlgfvd7;
                     publicKeyMultibase=zQ3sheWesAS13yhm6HYUwLqhZoBLHfWuT721feVqbVFR3w7hP}}
service            : {@{id=#atproto_pds; type=AtprotoPersonalDataServer;
                     serviceEndpoint=https://amanita.us-east.host.bsky.network}}

@matthewstreeter
Copy link
Author

I'm back at my desk now. I'll give the code block a shot in a moment.

Here is the (Get-BskySession).diddoc output:
`PS /Users/matthew/Documents/Scripting> (Get-BskySession).diddoc

@context : {https://www.w3.org/ns/did/v1, https://w3id.org/security/multikey/v1,
https://w3id.org/security/suites/secp256k1-2019/v1}
id : did:plc:6sa7bzdm7behw6k45oaprg7f
alsoKnownAs : {at://matthewrstreeter.com}
verificationMethod : {@{id=did:plc:6sa7bzdm7behw6k45oaprg7f#atproto; type=Multikey;
controller=did:plc:6sa7bzdm7behw6k45oaprg7f;
publicKeyMultibase=zQ3shkW3pzC8TyxNmCeror2d4PCrx3bA6vcJiH9jz3ykf93vq}}
service : {@{id=#atproto_pds; type=AtprotoPersonalDataServer;
serviceEndpoint=https://velvetfoot.us-east.host.bsky.network}}`

@jdhitsolutions
Copy link
Owner

The session looks right, which shouldn't be a surprise since most of the module commands work.

@jdhitsolutions
Copy link
Owner

A Bluesky user confirmed no problems using a Mac so the issue is something about your account. I think this means creating the credential with your pre-custom name. First, try to get your profile with the old name. I'm not sure it will work.

@matthewstreeter
Copy link
Author

I think I did things as instructed here. I stored my Bsky pass in a variable.

Screenshot 2024-11-11 at 4 29 41 PM

@jdhitsolutions
Copy link
Owner

That's the same problem. The repo is your username, which is getting pulled from the credential. I don't understand why the repo endpoint can't find the name.

@matthewstreeter
Copy link
Author

My non-custom domain profile url still loads

Unfortunately no luck getting authenticated unless I did something wrong in my quick attempt.

Screenshot 2024-11-11 at 4 40 29 PM

@jdhitsolutions
Copy link
Owner

I stripped everything down to the bare essentials in this script file.

Param(
    [PSCredential]$Credential
)

$message = "This is a debug test Bluesky message sent from VSCode."

$user = $credential.UserName
$pw = $credential.GetNetworkCredential().Password
$PDSHOST = 'https://bsky.social'

#create a session
$headers = @{'Content-Type' = 'application/json'}
$body = @{
    'identifier' = $user
    'password'   = $pw
} | ConvertTo-Json

$s = Invoke-RestMethod -Uri "$PDSHOST/xrpc/com.atproto.server.createSession" -Method Post -Headers $headers -Body $body
$headers.Add('Authorization', "Bearer $($s.accessJwt)")

$apiUrl = "$PDSHOST/xrpc/com.atproto.repo.createRecord"
$record = [ordered]@{
    '$type'   = 'app.bsky.feed.post'
    text      = $Message
    createdAt = (Get-Date -Format 'o')
}
$body = @{
    repo       = $Credential.UserName
    collection = 'app.bsky.feed.post'
    record     = $record
} | ConvertTo-Json -Depth 7

Invoke-RestMethod -Uri $apiUrl -Method Post -Headers $headers -Body $body -Verbose

Save this as a .ps1 file. Then run script-fullname.ps1 $YourCredential and see if it runs without errors. It just worked for me in VSCode. Is your credential user name matthewrstreeter or matthewrstreeter.com?

@matthewstreeter
Copy link
Author

Tried from my Windows machine with the same results bummer!

image

@matthewstreeter
Copy link
Author

I posted before seeing your recent post. I'll give that a try.

Store credential in SecretManagement

$username = 'matthewrstreeter.com'

@jdhitsolutions
Copy link
Owner

That is what I would expect and since the other commands work, I didn't think that should be a problem.

@thedavecarroll
Copy link

thedavecarroll commented Nov 11, 2024

I initially had the same issue.

  • My login account is user@thedavecarroll.com
  • My handle is @thedavecarroll.com
    • actually dropping the @ worked.

Running 7.4.6 on MacOS 14.7.1.

Instead of using the email account I use to login to Bluesky, I used my did and that worked, as did my domain name.

I can run more commands later tonight if needed.

Might be worth mentioning that an entity could use subdomains for multiple people using the .well-known non-DNS method as mentioned in How can I set and manage multiple subdomain handles?.

@matthewstreeter
Copy link
Author

Just tried this from my Windows system

image

@jdhitsolutions
Copy link
Owner

@thedavecarroll When you define your credential for use with this module, what do you set for the username?

@thedavecarroll
Copy link

thedavecarroll commented Nov 11, 2024

I used:

  • dave@thedavecarroll.com
    • failed
    • my login
  • @thedavecarroll.com
    • failed
    • what the Bluesky app shows aa my handle
  • did:plc:rlwd5iajr3btl5e7gyvfwk67
    • succeeded
  • thedavecarroll.com
    • succeeded

@thedavecarroll
Copy link

This helped me.

https://bsky-debug.app/handle

@matthewstreeter
Copy link
Author

I tried the did:xyzabc value for the repo and that was the trick (at least from my Windows machine so far)

image

@thedavecarroll thanks for posting that the DID value worked for you.

@jdhitsolutions jdhitsolutions added the bug Something isn't working label Nov 12, 2024
@jdhitsolutions jdhitsolutions self-assigned this Nov 12, 2024
@matthewstreeter
Copy link
Author

I created a new Bluesky test account without a custom domain (matthew-test.bsky.social).

I saw the same error posting to that on my Mac system but I had success posting on my Windows system.

Screenshot 2024-11-13 at 8 28 16 PM

@jdhitsolutions
Copy link
Owner

I think we've narrowed down the problem is OS-related. The module works fine on Windows. And it mostly works on a Mac except for posting a message. This is going to take some external research.

@jdhitsolutions
Copy link
Owner

Does the Mac do any sort of proxy filtering?

@jdhitsolutions
Copy link
Owner

I can see your test profile.

image

And search for it in the browser

image

Which indicates there is nothing wrong with the account itself. Only when the Mac attempts to resolve and validate the account name.

@matthewstreeter
Copy link
Author

matthewstreeter commented Nov 14, 2024 via email

@matthewstreeter
Copy link
Author

Well... I was just successful posting from my work Mac. I'm wondering if the install of the module on my personal Mac went wonky or I happened to mess that up.

@jdhitsolutions
Copy link
Owner

Curious. I'm assuming the same version of PowerShell is installed on both. Was your work Mac on the same network as the Mac Mini? I can't imagine what you would have messed up installing the module.

@matthewstreeter
Copy link
Author

matthewstreeter commented Nov 14, 2024

This is so strange. No luck posting from personal Mac after a fresh uninstall and reinstall of the module either.

Both are on 7.4.6 core. My personal Mac is a new M4 Mac Mini, my work Mac is a M1 MacBook Pro.

Same network too. Wired on my home network.

@jdhitsolutions
Copy link
Owner

That is odd and frustrating because we're running out of things to test. I'm assuming PowerShell commands and other modules work just fine on the mini.

@jdhitsolutions
Copy link
Owner

Can you do any type of network capture like Wireshark to compare the New-BskyPost on each system?

@jdhitsolutions
Copy link
Owner

Is the Mac Mini using a VPN or is private relay configured?

@matthewstreeter
Copy link
Author

I can post to my test account from my Mac Mini actually. It seems to be specific to my username as I cannot seem to use the New-BskyPost cmdlet for my 'matthewrstreeter.com' handle but I can post to my 'matthew-test.bsky.social' handle from any of my Macs.

Nothing on the Mac Mini for VPN or Private Relay either. Just rebooted too just be sure there 😄

@matthewstreeter
Copy link
Author

matthewstreeter commented Nov 14, 2024

From my Mac Mini trying to post to my test account first and then my primary account.

image

Missed this bottom part showing I was able to get my profile
image

@jdhitsolutions
Copy link
Owner

I'm curious if the debug web page shows different results. I'm expecting if you open https://bsky-debug.app/handle?handle=matthew-test.bsky.social in a browser on both systems that they will show the same thing. Is the same true when opening https://bsky-debug.app/handle?handle=matthewrstreeter.com ?

@matthewstreeter
Copy link
Author

Yessir. Both links output the same results on both Macs.

Mac Mini
image

MacBook Pro
image

@jdhitsolutions
Copy link
Owner

Here's another test script.

Param(
    [PSCredential]$Credential,
    [string]$Repo = "jdhitsolutions.com"
)
$user = $credential.UserName
$pw = $credential.GetNetworkCredential().Password
$PDSHOST = 'https://bsky.social'

#create a session
$headers = @{'Content-Type' = 'application/json' }
$body = @{
    'identifier' = $user
    'password'   = $pw
} | ConvertTo-Json

$s = Invoke-RestMethod -Uri "$PDSHOST/xrpc/com.atproto.server.createSession" -Method Post -Headers $headers -Body $body
$headers.Add('Authorization', "Bearer $($s.accessJwt)")

$apiUrl = "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$repo&collection=app.bsky.feed.post&limit=5"

$splat = @{
    Uri                     = $apiUrl
    Method                  = 'Get'
    Headers                 = $headers
    ErrorAction             = 'Stop'
    OutVariable             = 'global:ov'
    ResponseHeadersVariable = 'global:rh'
    Verbose                 = $true
}

$r = Invoke-RestMethod @splat
$r.records.value | Select CreatedAt,Text

If I use your test name, this works as expected.

image

But it fails with your other account name.

image

However, I can get your DiD ( did:plc:6sa7bzdm7behw6k45oaprg7f) from your profile, and that WILL work.

image

There is something about the com.atproto.repo endpoint that can't resolve matthewrstreeter.

@jdhitsolutions
Copy link
Owner

Try my test repo list script on both systems testing both account names and the DID of your DNS account and see if you get the same results I do.

@jdhitsolutions
Copy link
Owner

I'm getting some guidance from the Bluesky developer's Discord. I may need to revise my code to use the DiD instead of an account handle.

@jdhitsolutions
Copy link
Owner

Holding off on any more testing until Bluesky's network issues are resolved.

@matthewstreeter
Copy link
Author

matthewstreeter commented Nov 14, 2024

Did I break everything haha? 😆 /s

@jdhitsolutions
Copy link
Owner

I made a major change to the posting command in the latest version. Update to v1.3.0 and let's see if this makes a difference.

@matthewstreeter
Copy link
Author

Success!

image

@jdhitsolutions
Copy link
Owner

Excellent. It appears some API endpoints don't work well with handles so I revised commands to use the accounts DID where it was supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants