Unable to create android application to Create,Destroy channels on Amazon IVS

Viewed 8

I want to create an android application, to create,destroy and add participants to, an Amazon IVS channel from the app but I am unsure about the API endpoints that would be required.

I started creating channel using this page

and using API endpoints from this page

But I keep getting response code as 403 or 401 :

Here is my code:

MainActivity:

const val BASE_URL_IVS= "https://ivs.us-east-1.amazonaws.com/"
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    createChannel()
}

private fun createChannel() {
    val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
    val retrofit = Retrofit.Builder()
        .addConverterFactory(MoshiConverterFactory.create(moshi))
        .baseUrl(BASE_URL_IVS)
        .build()
        .create(CreateChannelApiInterface::class.java)

    val reqObj = CreateChannelReq(authorized = "true", latencyMode = "LOW",
        name = "VFirst", tags = Tags(string = "First"), type = "BASIC" )
    val retrofitPassData  = retrofit.passDataChannel(reqObj)

    retrofitPassData.enqueue(object : Callback<CreateChannelResponse?> {
        override fun onResponse(
            call: Call<CreateChannelResponse?>,
            response: Response<CreateChannelResponse?>
        ) {
            Log.d("MainActivity", response.body().toString())
            Log.d("MainActivity", response.code().toString() )
        }

        override fun onFailure(call: Call<CreateChannelResponse?>, t: Throwable) {
            Log.d("MainActivity", "Failure POST!! "+t.message )
        }
    })
}

Code of CreateChannelApiInterface :

interface CreateChannelApiInterface {

@POST("CreateChannel")
fun passDataChannel(@Body data:CreateChannelReq):Call<CreateChannelResponse>
}

Output in Logcat:

 2022-09-22 12:01:57.821 10859-10859/com.himanshukumargupta.camerastreaming D/MainActivity: null
 2022-09-22 12:01:57.821 10859-10859/com.himanshukumargupta.camerastreaming D/MainActivity: 403



I also followed a different article, to create using CloudFormation Stack

and created the cloud formation stack on AWS as guided but receiving the same error.

My Code in MainActivity:

const val BASE_URL_V = "https://309cxfteq0.execute-api.us-east-1.amazonaws.com/abcd-ivscreate/"
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

 //        getMyData()
    createChannel()
}

private fun createChannel() {
    val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
    val retrofit = Retrofit.Builder()
        .addConverterFactory(MoshiConverterFactory.create(moshi))
        .baseUrl(BASE_URL_V)
        .build()
        .create(CreateChannelApiInterface::class.java)

    val reqObj = CreateChannelReq(authorized = "true", latencyMode = "LOW",
        name = "VFirst", tags = Tags(string = "First"), type = "BASIC" )
    val retrofitPassData  = retrofit.passDataChannel(reqObj)

    retrofitPassData.enqueue(object : Callback<CreateChannelResponse?> {
        override fun onResponse(
            call: Call<CreateChannelResponse?>,
            response: Response<CreateChannelResponse?>
        ) {
            Log.d("MainActivity", response.body().toString())
            Log.d("MainActivity", response.code().toString() )
        }

        override fun onFailure(call: Call<CreateChannelResponse?>, t: Throwable) {
            Log.d("MainActivity", "Failure POST!! "+t.message )
        }
    })
}

Code of CreateChannelApiInterface :

interface CreateChannelApiInterface {

@POST("POST")
fun passDataChannel(@Body data:CreateChannelReq):Call<CreateChannelResponse>
}

Output in Logcat:

2022-09-22 12:14:24.031 11505-11505/com.himanshukumargupta.camerastreaming D/MainActivity: null
2022-09-22 12:14:24.031 11505-11505/com.himanshukumargupta.camerastreaming D/MainActivity: 403


I am quite new to this and stuck on this problem for days. If somebody can look into the issue and provide the solution it would be great.

Thank you

0 Answers
Related