Meta's Threads Client for Ruby
Tags: threads, ruby, rubygem
Published: 2023-07-12 14:54:34

In today's digital landscape, social media platforms have become integral to our personal and professional lives. Meta's Threads, a popular social media platform, provides users with a powerful means of communication and sharing content. To enhance the development experience for Ruby developers, we are thrilled to introduce **Threads Client Ruby**, a comprehensive library that simplifies the process of creating engaging posts with text, images, links, and replies on Meta's Threads.

🚀 Public repo: [Threads Client Ruby](https://github.com/dereknguyen269/threads_client_ruby)

## 📌 Key Features and Benefits:

- ✅ [Text Threads](#✨-threads-with-image)
- ✅ [Threads with Image](#✨-threads-with-image)
- ✅ [Threads with Link Attachment](#✨-threads-with-link-attachment)
- ✅ [Get Post Id From URL](#✨-get-post-id-from-url)
- ✅ [Reply to Other Threads](#✨-reply-to-other-threads)
- ✅ [Like/Unlike a Thread](#✨-likeunlike-a-thread)
- ✅ [Follow/Unfollow a User](#✨-followunfollow-a-user)
- ✅ [Delete a Post](#✨-delete-a-post)

## Getting Started:

To start leveraging the power of Threads Client Ruby for creating captivating posts on Meta's Threads, follow these simple steps:

- Install the Gem: Install the gem by executing the following command in your Ruby environment: gem install threads_client.

```
gem install threads_client_ruby
```

## Usage:

### 🌀 Config Threads

Using **username** and **password** (first time)
```ruby
credentials = {
  username: "Instagram's username",
  password: "Instagram's password"
}

ThreadsClientRuby.config do |config|
  config.credentials = credentials
end
```

Using **usertoken** and **userid** (get from [here](#🤖-get-usertoken-and-userid))
```ruby
credentials = {
  usertoken: "token received after login successfull",
  userid: "Instagram's user id"
}

ThreadsClientRuby.config do |config|
  config.credentials = credentials
end
```

>💡 TIP: Using **usertoken** and **userid** to avoid Theard rate limit and decrease response time.

#### 🤖 Get usertoken and userid

```ruby
  userinfo = ThreadsClientRuby.get_userinfo
  # {
  #   :usertoken=> "eyJkc191c2VyX2lkIjoiNTgzOTIyMTY....",
  #   :userid=>"583922..."
  # }
```

**✨ Text Threads**

```ruby
ThreadsClientRuby.publish(text: 'Hello World!')
```

##### ✨ Threads with Image

```ruby
# Online image path
ThreadsClientRuby.publish(text: 'Hello World!', image: 'https://fastly.picsum.photos/id/654/536/354.jpg?hmac=Nqd_oi3EIiPJBAVPYhIUjaEvKpRqLjhtTHkxPmjjo7M')

# Or with local image path
ThreadsClientRuby.publish(text: 'Hello World!', image: '/Users/local-path/logo.jpg')
```

##### ✨ Threads with Link Attachment

```ruby
ThreadsClientRuby.publish(url: 'https://github.com/dereknguyen269/threads_client_ruby')
```

##### ✨ Get Post Id From URL

```ruby
post_id = ThreadsClientRuby.get_post_id('https://www.threads.net/t/CugF-EjhQ3r')
# => 3143538795635609067
```

###### ✨ Reply to Other Threads

```ruby
ThreadsClientRuby.publish(reply_id: post_id, text: "Reply to #{post_id}")
```

Conclusion:

Threads Client Ruby provides Ruby developers with a seamless and efficient solution for creating engaging posts on Meta's Threads. With support for text, images, links, and replies, this gem empowers developers to build innovative social media tools, automate posting processes, and enhance user experiences on the platform. Unlock the potential of Meta's Threads and captivate your audience with captivating posts using Threads Client Ruby today.