I'm trying to use the latest version of the youtube API (V3) but for some reason I'm getting casting exception when calling the list functions (for the different entities)
in the below example I'm getting the following exception when calling the execute method:
Code:
Youtube youTube = new Youtube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).build();
Map<String, Channel> channels = youTube.channels().list("id").setMine("").execute().getChannels();
Exception:
java.lang.IllegalArgumentException: expected collection or array type but got java.util.Map<java.lang.String, com.google.api.services.youtube.model.Channel> [key channels, field private java.util.Map com.google.api.services.youtube.model.ChannelListResponse.channels]
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:115) ~[guava-11.0.1.jar:na]
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:534) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.json.JsonParser.parse(JsonParser.java:352) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:588) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.json.JsonParser.parse(JsonParser.java:291) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.json.JsonParser.parse(JsonParser.java:268) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.json.JsonParser.parseAndClose(JsonParser.java:143) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.http.json.JsonHttpParser.parse(JsonHttpParser.java:90) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:501) ~[google-http-client-1.11.0-beta.jar:1.11.0-beta]
at com.google.api.services.youtube.Youtube$Channels$List.execute(Youtube.java:271) ~[google-api-services-youtube-v3alpha-rev13-1.8.0-beta.jar:na]
Any idea? I'm using the latest java client.
Thanks,
Efi
There was just a recent, significant push on the server side that changed the response format for a number of services, and not all the client libraries have been updated yet to deal with that. Try refetching the Java client library service definition for YouTube early next week and trying again.
Related
I am writing a Slack integration that can boot certain users out of public channels when certain conditions are met. I have added several OAuth scopes to the bot token, including the following:
channels:history
channels:manage
channels:read
chat:write
chat:write.public
groups:write
im:write
mpim:write
users:read
I am writing my bot in Python using the slack-bolt library and asyncio. However when I try to invoke this code:
await app.client.conversations_kick(channel=channel_id, user=user_id)
I get the following error:
slack_sdk.errors.SlackApiError: The request to the Slack API failed. (url: https://www.slack.com/api/conversations.kick)
The server responded with: {'ok': False, 'error': 'channel_not_found'}
I know for a fact that both the channel_id and user_id arguments I'm passing in are valid. The channel ID I'm using is the string C01PAE3DB0A. I know it is valid because I can use the very same value for channel_id in the following API call:
response = await app.client.conversations_info(channel=channel_id)
And when I call conversations_info like that I get all of the information about my channel. (The same is true for calling users_info with the user_id - it returns successfully.) So why is that when I pass my valid channel_id parameter to conversations_kick I consistently receive this channel_not_found error? What am I missing?
So I got in touch directly with Slack support about this and they confirmed that there is a bug on their end. Specifically, the bug is that I should have received a restricted_action error response instead of a channel_not_found response. Apparently this is a known issue that is on their backlog.
The reason the API call would (try to) return this restricted_action error is simply because there is a workspace setting that, by default, prevents non-admins from kicking people out of public channels. Furthermore, this setting can only be changed by the workspace owner - one tier above admins.
But assuming you are the owner of the Slack workspace, you simply have to log into the Settings & Permissions page, which should look something like this:
And then you have to change the setting labeled "People who can remove members from public channels" from "Workspace admins and owners only (default)" to "Everyone, except guests."
Once I made that change, my API calls started succeeding.
I call YT.Channel API with a list of Ids and I get an error:
GoogleJsonResponseException: API call to youtube.channels.list failed with error: Request contains an invalid argument.
YouTube.Channels.list('id, snippet, statistics', {
id: resultsParentChannelIdsPerPage.join()
}).getItems()
id = UC5JU3rLOMvB7ZIXI2oi1ubg,UC4mKtxAtWQgmkFC6S6siNVg,UC-4hR9ralZoAW15tAwSbJ_A,UCvdwiASqQrIIozQcVAXvRXw,UCUIKx2bIjRcBWyIa3AQGSCg,UClkJAMCknefAzrYfpk1_0Nw,UCsDm3gAWuDRDLMjZLoUxOuA,UC-OkSUXpLrS2eBpztAJ78wg,UCb6RivygioXGs0icq4McBd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qg,UCPWsJzhhZSPlfQ7DOjSA4Fg,UCPKKa8RgdfoMRBkyt8BhIqA,UCa3bfoq50eqErBDgq0p2cQA,UCyH05wKVW-96Lz2mqhGnzVw,UCiXjl5HwqmuCjr5ZmW00csQ,UCA9tlIHeg-k8z3PUpozkUmA,UC_Bc8M2p5fpYqlfWvbVmw2g,UCnD86huZnRWKDMZISbQx6kg,UCtRn5U4Uz2vbREF0qD0TLuA
I didn't get this in previous similar runs. What has changed?
API explorer
Nothing has changed, as far as I know. Fact is that -- with the exception of CommentThreads.list, Comments.list and Members.list endpoints -- all YouTube Data API endpoints that are providing result sets would not return result sets of more than 50 items.
Therefore, when using the Channels.list endpoint's request parameter id, you'll have to limit yourself to pass to it a comma-separated list of channel IDs of at most 50 elements.
I am trying integrate the new Twitter API specifically the streaming tweets part in my android app, I am using Retrofit for my http calls.
When I try to make the call to get the streaming tweets it just hangs and does not return anything.
this is my retrofit call
#Streaming
#GET("tweets/search/stream")
suspend fun getFilteredStream(#Header("Authorization") token:String)
I then tried making a call with just OkHttp as shown in the documentation I get a successful response but I dont know how to stream the data.
I can make the call successfully via a curl call and see the data no problem.
How do I stream the data via retrofit or OkHttp
Update:
With OkHttp I was able to get data by doing this
val client: OkHttpClient = OkHttpClient().newBuilder()
.build()
val request: Request = Request.Builder()
.url("https://api.twitter.com/2/tweets/search/stream")
.method("GET", null)
.build()
val response: Response = client.newCall(request).execute()
val source = response.body?.source()
val buffer = Buffer()
while(!source!!.exhausted()){
response.body?.source()?.read(buffer, 8192)
val data = buffer.readString(Charset.defaultCharset())
}
data holds the string data representation of multiple tweet objects but how do I read one tweet at a time, or parse the response like this?
From the docs, I think you'll need to combine the two examples you have.
https://github.com/square/retrofit/blob/108fe23964b986107aed352ba467cd2007d15208/retrofit/src/main/java/retrofit2/http/Streaming.java
Treat the response body on methods returning {#link ResponseBody ResponseBody} as is, i.e. without converting the body to {#code byte[]}.
And example calling code
https://github.com/square/retrofit/blob/108fe23964b986107aed352ba467cd2007d15208/retrofit/src/test/java/retrofit2/CallTest.java#L599
I suspect, dependending on the JSON API you use you may be able to use a Streaming API from the response body. But if not you could split on either just newline or newline followed by { on next line and parse individually. Sorry I can't help here.
See https://en.wikipedia.org/wiki/JSON_streaming#Concatenated_JSON
On November 13th, I got a call from a customer reporting that the YouTube player didn't work anymore. After a quick look in the dev tool, I found that there was an error:
Uncaught TypeError: a.getVideoData is not a function
Looking into what the player object was containing, I learned that there's no function getVideoData anymore.
The function getVideoData provided a way to get the video title. Now, how can I get the title?
Is there any article from Google about this change?
To get a video's title, you can query the YouTube Data API v3:
GET https://www.googleapis.com/youtube/v3/videos
?part=snippet
&id=VIDEO_ID
&key=YOUR_API_KEY
For that you need to sign up on the Google Cloud Console and create an API key (it's free). You can restrict the API key to only be used from your website, that way you can safely make it public in your JS source code/html code without others being able to make queries on your behalf. Make sure to enable the YouTube Data API v3 in the console as well, otherwise your queries will return errors.
The above query will return a JSON representation of the information on the video that you are interested in (the snippet part). Say you parse the JSON into an object called result. Then you can get the video title via
result.items[0].snippet.title
getVideoData() seems to be back (Dec, 2017). So, try again !
As of today (October 1st, 2020), I am retrieving the title of the video from within YouTube's API object:
// Assigning YouTube's ID to your ID variable
const playerID = "xxxxxxx";
// Creating an object for the video using YouTube's API.
const yPlayer = new YT.Player(playerID, {
events: {
'onReady': onPlayerReady(),
'onStateChange': onPlayerStateChange()
}
});
function onPlayerReady() {
}
function onPlayerStateChange() {
// Title retrieved here
let videoTitle = yPlayer.j.videoData.title;
}
onYouTubeIframeAPIReady();
I was upgrading Twilio node from 2.x to 3.x with this guide.Twilio's current version in my system is 3.6.3 and typings for Twilio(#types/twilio) is 0.0.9.I have imported twilio in my code as
import * as Twilio from "twilio";
In 2.x,new instance of Twilio was created as
const twilio=new Twilio.RestClient(accountSid, authToken);
However this does not work in 3.x. When I console logged twilio nothing gets printed and also Iam not getting any error.As mentioned in tutorial,I tried using
const twilio=new Twilio(accountSid, authToken);
This shows the following error,
Only a void function can be called with the 'new' keyword.
'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
Similar question with no answer.
Is this problem because typings of Twilio(#types/twilio) is not updated to support version 3.x?(Iam also unable to find method fetch() in typings).
I think this problem is because the typings for Twilio (#types/twilio version:0.09) is not compatible with Twilio 3.x.
Feature Request for typings for Twilio 3.x :- https://github.com/twilio/twilio-node/issues/250
Related Issue:- https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18992