This Project creates a Mastodon Client for the Apple Watch that allows for simple Toot activities ("Favourite", "Boost", "Bookmark".)
Simple Toot interaction occurs on the Watch App, while settings and signing in happens on the companion iPhone app.
(Please note that the objectives have not been implemented yet.).
iPhone app:
- Log into an instance
Watch App:
- View user's timelines on instance
- "Favourite" a Toot
- "Boost" a Toot
- "Bookmark" a Toot
A Mastodon Access Token is required before running the project. This token is placed into a plist file in order to run.
I personally used Postman for getting the tokens, but any API inspector tool will do. Before getting an access token, you must first get a client ID and a client access key from Mastodon. Steps are listed below, with additional notes on doing it through Postman.
Request a ClientID and ClientSecret
- Copy and paste the curl command from the above link into your desired API inspection tool (in Postman: After creating a workspace, click "Import" on the top left near the workspace name, and copy/paste the curl command into the text field that comes up. Postman will create a POST command for you.)
- Replace "mastodon.example" with your desired mastodon instance
- Send your POST command using the API inspector tool used
- Save off the contents somewhere for future use. Most important will be the client_id and the client_secret
Use the Authorization GET Request to get the Authorizaton Code
- Click the link above and copy/paste the https command somewhere you can edit it
- replace "mastodon.exmaple" with your mastodon instance and "CLIENT_ID" with your client id
- remove the line endings so that the command is one long string
- copy/paste this string into your browser
- it will bring you to your instance login page. Log into your account
- will ask you to grant access based upon the request made
- copy the authorization code and store it somewhere safe
Use the Authorization Code to get the Access Token
- Click the link above to get the needed curl command and place it into an API inspector tool (in Postman: use "Import" like in the previous section")
- Replace client_id, client_secret, and code with your client_id, client_secret, and authorization_code
- Execute the POST command using the API inspector tool and save off the results
- The results include your Access Token
Test your token before jumping into Xcode - it can save a lot of time.
- Copy/paste the below curl command into your API inspector tool
curl
-H 'Authorization: Bearer our_access_token_here'
https://mastodon.example/api/v1/accounts/verify_credentials
- replace "mastodon.example" with your mastodon instance
- replace "our_access_token_here" with your access token within the header section of the API tool used. (Note - make sure there is a space between "Bearer" and your access token)
- You should see your credentials show up
The above steps provide a method to getting an access code. Please also refer to the Mastodon API documentation if more information is needed.
The project currently uses a plist file that is used to place the access token needed for API calls. You will be creating a new plist file with the access code just generated. This should allow you to access your instance.
The following steps are needed to successfully run the app:
- Clone, Fork, or Download the project for personal use
- Create a copy of the "TokensExample.plist" file and rename it to "Tokens.plist" (spelling is important so that you don't accidentally commit your token to the repo)
- Copy/Paste your personal Access Token to the "Tokens.plist" file
- Navigate to the "MastodonNetworking.swift" file and replace "Mastodon.example" with your instance in the mastodon instance variable
- Compile and Run "Stray Toots" for the companion iPhone app
- Compile and Run "Stray Toots Watch App" for the Watch App (which will have the Toots)
This README, and it's project, is a continual work in progress. Although there are good Swift Package Managers that can make some of these tasks much easier, I wanted to initially make sure I understand some basic networking concepts and can read and understand API documentation. I also want to start Toot-ing as much as I Tweet.
Update July 2023 - making this project Open Source in case others would like to learn from it or develop it into something else, as I don't have the personal bandwidth to properly support it for a while.
This Project is covered by the MIT License.