Youtube API - Allows Subscribe User but takes away next day - youtube-api

we have a product that will subscribe a user to another user(s) after they go through and give us full permission to do so. The user is then subscribed to these other user(s) ... you can see this in youtube after the API is performed (seems successful) ... but a day later the subscribers are removed and gone? This always worked well. Anyone experience similar issues or know the why here?
When using the API with full permission scope, we Subscribe the user to a channel and we get varying results :
the Google_Service_YouTube_Subscription_Object is returned with valid data
The channel Subscription https://www.youtube.com/subscribers?ar=2&o=U may or may not increase in value (counter at top)
The channel Subscriber list https://www.youtube.com/subscribers?ar=2&o=U is not showing the new user (subscriber)
The user shows in their Youtube view that they are subscribed to the Channel
the user Comment on the video is displayed depending on the user privacy settings
the user Like on the video is counted
the NEXT day: comments, subscriber counts are removed from the Channel, likes on the video seems to stay
$youtube_client = new \Google_Client();
$youtube_client->setClientId(xxxx);
$youtube_client->setClientSecret(xxxx);
$youtube_client->setScopes(xxxx);
$youtube_client->setRedirectUri(xxxx);
$youtube = new \Google_Service_YouTube($youtube_client);
$resourceIdyt = new \Google_Service_YouTube_ResourceId();
$resourceIdyt->setChannelId($channel);
$resourceIdyt->setKind('youtube#channel');
$subscriptionSnippetyt = new \Google_Service_YouTube_SubscriptionSnippet();
$subscriptionSnippetyt->setResourceId($resourceIdyt);
$subscriptionyt = new \Google_Service_YouTube_Subscription();
$subscriptionyt->setSnippet($subscriptionSnippetyt);
$subscriptionResponse = $youtube->subscriptions->insert('id,snippet', $subscriptionyt, array());

Related

Twilio SWIFT API get consumed messages always returns 0

I want to display next to a chat channel the number of messages a channel has that have been unconsumed or unread (I assume this is what unconsumed means?)
Currently I send messages to a channel that two users are subscribed to , a private chat. Then before opening up the chat window I check the channel for unconsumed messages, but it always say 0 messages even if I call setNoMessagesConsumedWithCompletion.
I am using the Swift API...What do I need to do to find out how many messages in my channel have not been read yet? At what point do they become read? (when the user opens up a chat channel and requests to getLastWithCount?)
I read in the docs you have to set something called the consumption horizon to get unconsumed message, but I don't know how you do that in SWIFT API https://www.twilio.com/docs/chat/consumption-horizon also this was for Javascript API so perhaps it is easier with Swift Api?
I figured out the solution. As per the documentation you need to update the last consumed message index. So for example if the user has a chat window open you need to record for that user (or instance of the Chat Client) what was the last message they saw before they close their chat. I am storing all the messages in a message array and update the last consumed message index with the length of the array of messages:
generalChannel?.messages?.setLastConsumedMessageIndex(NSNumber.init(value: self.messages.count), completion: { (result, count) in
if !result.isSuccessful() {
print(result.error.debugDescription)
}
})
Then if you send messages to that channel when the user is not in the channel these will be recorded as unconsumed, you can get the number by calling:
channel.getUnconsumedMessagesCount(completion: { (results, numberUnconsumed) in
print(numberUnconsumed)
})

Twilio Chat getChannels order by most recent message

In twilio chat, is there a way to specify an order to the getChannels() method? Or is there a property on the Channel object that will tell me when the last message sent on that channel was? The dateUpdated property on Channel seems to be when properties on the channel were updated, not including messages sent/received.
I would like to order my channels list by the most recent messages. And I would like to do this without having to retrieve all the messages first.
You can add the attributes parameter upon updating a channel.
An optional string metadata field you can use to store any data you
wish.
You could track time/date info of messages here.
# Update the channel
service = client.services.get(sid="CHANNEL_SID")
channel = service.channels.create()
response = channel.update(friendly_name="NEW_FRIENDLY_NAME", attributes="ANY_DATA_YOU_WISH")
print(response)
You should then be able to subscribe to a channel event (JavaScript SDK example). As you did not specify what language you're using you will also find more details in the API Docs for iOS and Android SDKs as well.
// A channel's attributes or metadata have changed.
messagingClient.on('channelUpdated', function(channel) {
console.log('Channel updates: ' + channel.sid);
});

How can a Slack bot detect a direct message vs a message in a channel?

TL;DR: Via the Slack APIs, how can I differentiate between a message in a channel vs a direct message?
I have a working Slack bot using the RTM API, let's call it Edi. And it works great as long as all commands start with "#edi"; e.g. "#edi help". It currently responses to any channel it's a member of and direct messages. However, I'd like to update the bot so that when it's a direct message, there won't be a need to start a command with "#edi"; e.g. "#edi help" in a channel, but "help" in a direct message. I don't see anything specific to differentiate between the two, but I did try using the channel.info endpoint and counting the number of people in "members"; however, this method only works on public channel. For private channels and direct messages, the endpoint returns an "channel_not_found" error.
Thanks in advance.
I talked to James at Slack and he gave me a simply way to determine if a message is a DM or not; if a channel ID begins with a:
C, it's a public channel
D, it's a DM with the user
G, it's either a private channel or multi-person DM
However, these values aren't set in stone and could change at some point, or be added to.
So if that syntax goes away, another way to detect a DM to use both channels.info and groups.info. If they both return “false” for the “ok” field, then you know it’s a DM.
Note:
channels.info is for public channels only
groups.info is for private channels and multi-person DMs only
Bonus info:
Once you detect a that a message is a DM, use either the user ID or channel ID and search for it in the results of im.list; if you find it, then you’ll know it’s a DM to the bot.
“id” from im.list is the channel ID
“user” from im.list is the user ID from the person DM’ing with the bot
You don’t pass in the bot’s user ID, because it’s extracted from the token
FYI as of July 2017, for "message.im" events (via your app's Event Subscriptions), the event payload seems to now return additional fields to detect if the message is coming from your own bot (pasted in here from my logs):
INFO[0012] got Slack message: (bot.SlackMessage) {
SlackEvent: (bot.SlackEvent) {
Type: (string) (len=7) "message",
EventTs: (string) (len=17) "1501076832.063834",
User: (string) ""
},
SubType: (string) (len=11) "bot_message",
Channel: (string) (len=9) "D6CJWD132",
Text: (string) (len=20) "this is my bot reply",
Username: (string) (len=15) "Myapp Local",
BotID: (string) (len=9) "B6DAZKTGG",
Ts: (string) (len=17) "1501076832.063834"
}
Slack have added Conversations API some time ago. You should use it to differentiate between PM/channel instead of relying on prefix.
From Conversations API documentation:
Each channel has a unique-to-the-team ID that begins with a single letter prefix, either C, G, or D. When a channel is shared across teams (see Developing for Shared Channels), the prefix of the channel ID may be changed, e.g. a private channel with ID G0987654321 may become ID C0987654321.
This is one reason you should use the conversations methods instead of the previous API methods! You cannot rely on a private shared channel's unique ID remaining constant during its entire lifetime.
Get conversation info using conversations.info method and check is_im flag. is_im == true means that the conversation is a direct message between two distinguished individuals or a user and a bot.
The info function is also available for private channels with the Slack API method groups.info. This works also for direct message channels with multiple participants, since they are a special form of private channels.
You can use groups.list to get the IDs of all private channels incl. direct message channels with multiple participants.
Note that groups.list will only return private channels, that the user or bot that the access token belongs to has been invited to.

How can I get all my subscribed channel using youtube api v3

I'm new to youtube api v3, and I have a problem when get all my subscribed channel. I've subscribed 65 channel but I can only get 50 each api call. So, Is there any way to get all?
Another thing is, I have a channelID, is there any api to check this channel in a list of my subscribed channel?
Youtube API restricts 50 results per call. In case you were asking whether you can get all 65 in the same call, then the answer is no. However, if you meant whether all 65 can be retrieved then, yes. You'll need to use the nextPageToken paramter value and pass it to the pageToken parameter which will take you to the next page. In code, it can be handled in the following way(as shown in the documentation):
var nextPageToken = '';
// This loop retrieves a set of playlist items and checks the nextPageToken
// in the response to determine whether the list contains additional items.
// It repeats that process until it has retrieved all of the items in the list.
while (nextPageToken != null) {
var playlistResponse = YouTube.PlaylistItems.list('snippet', {
playlistId: playlistId,
maxResults: 25,
pageToken: nextPageToken
});
Regarding your ChannelID problem, from your description I understand you want to check whether you are subscribed to a particular channel in case you have it's ID. I believe the Activities method of Youtube API should be able to help you out. Look at contentDetails.subscription property. I hope that resolves your problem.

Rails and Websockets: need some direction on a feature

In my rails app a User has a profile and this profile can be publicly accessible. I have been looking at using the Pusher gem (https://github.com/pusher/pusher-gem) to use for plug-and-play websocket usage with my app.
Basically I am wanting it so that if a user is looking at a public profile and the owner of that profile happens to update that profile then the front-end is updated with the new information and the user is notified on the front-end about the update.
Any help on where to get started would be great!
For each public profile have a unique channel name e.g. <user_name>-profile.
Whenever an updated occurs on the user user_name's profile trigger an event on the user's channel, passing the updated data.
data = update_profile()
Pusher.trigger( '<user_name>-profile', 'profile-updated', {:profile => data} )
On the profile page running the the browser have the code that listens to updates only on the relevant channel:
var pusher = new Pusher( APP_KEY );
var channel = pusher.subscribe( '<user_name>-profile' );
channel.bind( 'profile-updated', function( update ) {
// Update UI to show new profile information
// Show something to indicate that an update has occurred
} );
The one problem here is that you will be triggering an event even when nobody is viewing the public profile. If you wanted to fix that you would need to use WebHooks and keep track of whether or not a profile channel was occupied and only trigger the event if it is.

Resources