-->

How to programatically detect whether a particular

2020-05-08 09:03发布

问题:

I have an application to create and manage YouTube live events. It all works good. I've one last requirement in my app to detect whether the user has really enabled livestreaming for his account. Based on the result, my app will either proceed with event creation/management or simply exit.

Note: Currently this is detected as Google API exception

[The user is not enabled for live streaming. [403]].

But this exception not hit till we actually start preparing the broadcast. I need some way to detect it somewhat early in my logic.

回答1:

There is no other API exposed to detect if a user has not enabled live streaming.

How we handled this in my application was to begin preparing the broadcast. If at any point the liveBroadcasts endpoint returned the liveStreamingNotEnabled error, we would stop preparing the broadcast, and guide the user to enable live events on their YouTube account.

We gave the user the option to navigate to their Channel -> Status and Features page (https://www.youtube.com/features), and showed them where exactly to enable live streaming. Unfortunately, this page doesn't have a mobile version, making a bad UX, but there really isn't any other way.

Without an exposed API to enable live streaming, this is the best solution we could think of at the time.

If the user enabled live events and went back to the app, we would begin the broadcast setup process again, continuing successfully if the user had enabled Live Streaming on their account, and guiding them to the Features page once more if they still had not enabled the setting.



回答2:

I know it is a bit late, but I hope this solution helps someone who faces the same problem now:

As per JAL's answer, I created a dummy event before I start streaming, if it returns a 403 status code or liveStreamingNotEnabled error, I'd stop the broadcast and guide the user as to how he can enable live streaming on his channel. This feature can be enabled from (https://www.youtube.com/features), but as JAL also mentioned, this page has no mobile version with terrible UX so the user can't enable live streaming from his phone through this page.

So in order to overcome this problem, I created a webview and loaded the link (https://www.youtube.com/live_streaming_signup). This is the action of the button to enable live stream from the features page. Youtube handles the flow automatically from there on. After that, if the user wants to create an event again, I check the status code again to make sure streaming is enabled. If not, I load the webview again and so on.