Giter VIP home page Giter VIP logo

periscope-producer-api's Introduction

Maven Central

ChatEndpoint is implemented in version 1.2.0

Periscope Producer API

Java implementation of Periscope Producer API

This api lets you use Periscope Producer API which is announced with this post on twitter blog and lots of tech sites like Variety, VentureBeat, etc.

Installation

<dependency>
 <groupId>io.antmedia.api.periscope</groupId>
 <artifactId>PeriscopeAPI</artifactId>
 <version>1.2.0</version>
</dependency>

How To Use

Authorize the App

Firstly fill the Periscope API Private Beta Waitlist Form to get client id and client secret. It may take some time to have a reply from support. Btw, they are sometimes very quick to respond.

Two methods to authorize your application.

  1. Device Code

    Useful for hardware and software devices that don’t have access to a web browser.

    //create an AuthorizationEndPoint instance
    AuthorizationEndpoints authorizationEndpoint = PeriscopeEndpointFactory.getAuthorizationEndpoint();
    
    //make a create device code request
    CreateDeviceCodeResponse createDeviceCodeResponse = authorizationEndpoint.createDeviceCode(CLIENT_ID);
    
    //Follow the instructions 
    System.out.println("Go to this url: " + createDeviceCodeResponse.associate_url);
    System.out.println("Enter this user code: " + createDeviceCodeResponse.user_code);
    System.out.println("and come back here");
    
    CheckDeviceCodeResponse checkDeviceCode;
    do {
        System.out.println("Waiting for " + createDeviceCodeResponse.interval + " seconds to check device code");
        
        //wait for interval seconds to check device code
        Thread.sleep(createDeviceCodeResponse.interval * 1000);
    
        //make a check device code to test if user code is entered to associated url as mentioned above
        checkDeviceCode = authorizationEndpoint.checkDeviceCode(createDeviceCodeResponse.device_code, CLIENT_ID);
    			
    } while(!checkDeviceCode.state.equals("associated"));
    // save access and refresh token fields to use in later requests.
    		
  2. OAuth2 Authorization Code

    Useful for software that has access to a web browser.

    AuthorizationEndpoints authorizationEndpoint = PeriscopeEndpointFactory.getAuthorizationEndpoint();
    String code = "code returned by periscope";
    String redirect_uri = " redirect uri in your application";
    
    AuthorizationResponse authorizationResponse = authorizationEndpoint.authWithOauth2(AuthorizationEndpoints.GRANT_TYPE_AUTHORIZATION_CODE, 
    				code, redirect_uri, null, CLIENT_ID, CLIENT_SECRET);
    //save access token, refresh token variables

Create and Publish Broadcast

//Initialize Periscope Endpoint Factory by giving access and refresh token
PeriscopeEndpointFactory periscopeEndpointFactory = 
    new PeriscopeEndpointFactory(TOKEN_TYPE, ACCESS_TOKEN, REFRESH_TOKEN);
       
//get broadcast end point     
BroadcastEndpoints endpoint = periscopeEndpointFactory.getBroadcastEndpoints();
    
// get region end point
RegionEndpoints regionEndpoints = periscopeEndpointFactory.getRegionEndpoints();
   
//create broadcast
CreateBroadcastResponse createBroadcastResponse = 
      endpoint.createBroadcast(regionEndpoints.get(), false);
         
//createBroadcastResponse has all the required information you need for your encoder and player
//rtmp, hls, configuration etc.
   
//right now it is time to publish
String title = "test";
PublishBroadcastResponse publishBroadcastResponse = 
            endpoint.publishBroadcast(createBroadcastResponse.broadcast.id, title, true, 
                                       new Locale("tr", "TR").toString());

After you publish broadcast, start your encoder

Stop Broadcast

Just call BroadcastEndpoints' stopBroadcast function with the broadcast id that is returned in creating and publishing broadcast

endpoint.stopBroadcast(publishBroadcastResponse.broadcast.id);

Delete Broadcast

Just call BroadcastEndpoints' deleteBroadcast function with the broadcast id that is returned in creating and publishing broadcast

endpoint.deleteBroadcast(publishBroadcastResponse.broadcast.id);

Get Broadcast

Just call BroadcastEndpoints' getBroadcast function with the broadcast id to query the broadcast

Broadcast broadcast = endpoint.getBroadcast(publishBroadcastResponse.broadcast.id);
assertEquals(broadcast.id, publishBroadcastResponse.broadcast.id);
assertEquals(broadcast.state, "ended");
assertEquals(broadcast.title, title);

Build

Clone the repository

git clone https://github.com/ant-media/Periscope-Producer-API.git

cd Periscope-Producer-API/

mvn install

Then the created jar will be on target directory.

periscope-producer-api's People

Contributors

mekya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.