YouTube Data API: check if an user subscribed to me - youtube

I can't seem to see in the docs if there is a way, given an user ID, if that user follows my channel or not.
I saw this API:
https://developers.google.com/youtube/v3/docs/subscriptions/list?apix_params=%7B%22part%22%3A%5B%22snippet%2CcontentDetails%22%5D%2C%22mine%22%3Atrue%7D
but that seems to only list my subscriptions. Unless I misconfigured it.
Is this even possible?

Querying Subscriptions.list with mine=true will return the list of channels to which you -- the authenticated user -- subscribed.
For the other way around -- i.e. for a list of channels that are subscribers of your channel -- there are two other request parameters: myRecentSubscribers and mySubscribers.

Related

How to change Rails object fields after it's been paid via Stripe Checkout?

In my application, a user can create a draft of an object, and then on a "finalise" view they can check if they only want the standard price or one of the two extra features as well (e.g. their entry being featured on the platform) - these are stored as three separate products each with their own price because I want to be able to track them separately in the future.
I am using Checkout for payments and my backend is Rails.
I am listening to webhooks, but I don't know how I could actually modify the object in question, since I can't see any webhook request body that contains the information I need.
What I imagine I'd need is something like this: "there has been a successful charge of $x related to your object with id 123, and the charge included product prod_asdf and prod_sdfg", and then I could update e.g. the paid and featured boolean fields of my object.
This seems like a no-brainer, since the products and prices are actually handled by Stripe and they are passed to the checkout session, I don't see why I can't access them from the webhooks?
EDIT: I'm wondering if passing necessary metadata to the Session object and then using the same metadata listening to a checkout.session.completed event is a good idea.
You can link a Checkout Session back to your Listing object by including the related object ID in the metadata (https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-metadata) when you create the Checkout Session. When you listen for checkout.session.completed events, the event will come with a Checkout Session object. You can easily link the Checkout Session back to your Listing object by checking the metadata and it also has an amount_total field so that will tell you the total payment amount.
You can get the products included in a session from line_items (https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items). Unfortunately, line_items is not included in the webhook event by default since it is expandable (https://stripe.com/docs/expand). After receiving the checkout.session.completed event you can use the ID to retrieve the Checkout Session with line_items expanded like this:
session = Stripe::Checkout::Session.retrieve(
id: 'cs_test_xxx',
expand: ['line_items'],
)
line_items = session.line_items
Alternatively, you can just retrieve the Checkout Session's line items (https://stripe.com/docs/api/checkout/sessions/line_items) like this:
line_items = Stripe::Checkout::Session.list_line_items('cs_test_D3OF4MY1VGflR8idkewd795t8MLd4PwA3wxdLCHikdRFTIkBecH6FKij', {limit: 5})

ActionCable: How to check if user is subscribed to channel?

Situation:
I have a small chat app with two users in each room.
Lets call'em Sender and Receiver.
I'd like to make 'read/unread messages'.
To determine if Sender's message is currently being read he needs to know if Receiver is currently subscribed to the channel.
I'm trying to look through subscriptions:
# I can retrieve subscriptions from Redis:
redis_record = Redis.new.pubsub("channels", "action_cable/*")
# I can make such id
key = Base64.encode64("gid://test-app/User/1").tr('=', '').tr('actioncable/', '').chomp
But I don't know how to look for existing record.
Tried:
Redis.new.scan(0, match: key)
With no result.
Question: how to find out if subscription is active? (using Redis is not a keypoint, maybe ActionCable has something to do with it somewhere inside the box)

Trello API (Ruby/Rails) getting user's cards, boards, lists

I want to get particular data from Trello (using Trello API) knowing only user's trello id. I need to get all user's cards that has particular list names, and for all cards that meets requirements I need to get: card shortLink, list name, board name. The problem is I need to reduce waiting time. The only reasonable solution is to use less API requests. Here is my code:
userCards = JSON.parse(#a.get('/members/'+trello_id+'/cards?fields=shortLink,labels').body)
userCards.each do |card|
list = JSON.parse(#a.get('/cards/'+card['id']+'/list?fields=name').body)
if LIST.include?(list['name'].upcase)
board = JSON.parse(#a.get('/cards/'+card['id']+'/board?fields=name').body)
end
end
If you have any idea how to make this code work faster, I will be more than happy to hear that.

How do I get a users online status via the slack api?

the users active/away status does not appear to be listed here:
https://api.slack.com/types/user
is there another method to query this information that I missed?
Maybe you noticed it by now, but there is a method named users.getPresence in the Slack API.
Example of querying the API, given that you have created a token (token=xoxp-313xxxxxx-313xxxxxx-313xxxxxx-xxxxxx) and you are looking for the user with the ID U03xxxxxx.
curl -X POST https://slack.com/api/users.getPresence
--data "token=xoxp-313xxxxxx-313xxxxxx-313xxxxxx-xxxxxx&user=U03xxxxxx"
Response:
{"ok":true,"presence":"away"}
Note that you can get user ids, with the method users.list or users.info.
REF: https://api.slack.com/methods
Currently there's the status key on user objects returned from
https://slack.com/api/users.info
I think the most easier way for this > get all user presence status (up to 1000 users) quickly is the users.list method.
https://api.slack.com/methods/users.info
https://slack.com/api/users.list?token=xoxp-173888888-XXXXXXXX-YYYYYYYY-ZZZZZZZZ&presence=true&pretty=1
Please don't forget to read the documentation, sometimes the limit at 200.

How can I get all tweets relating to a specific user in Twitter?

I am new to the Twitter API and I'm having an issue with the user_timeline API.
I am using the following REST query:
https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=twitterapi&count=50
which is provides the user's timeline data, however it only gives the user's tweets; I want all tweets by and about the user (i.e. the user's tweets, and mentions of the user by the user's followers).
Thanks in advance!
You can access this by searching for the user's # handle. This will return tweets which mention #user and also tweets by #user.
Twitter API - Search
--
I've no experience about formatting for JSON calls but the following should be enough:
https://api.twitter.com/1.1/search/tweets.json?q=%40ataulm
The %40 is for the # symbol, and ataulm is the user name you wish to query. See the page linked for default values to the other parameters - this will, for example, only return 15 tweets per "page" (not sure what a page refers to), but can be set to a maximum of 100 per page, using the count parameter.
"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser.'&count=500'
BUt it is giving only 200 records.

Resources