Agora Unable to Start Cloud Recording - api

options1 = {
'method': 'POST',
'url': 'https://api.agora.io/v1/apps/' + appID + '/cloud_recording/resourceid/' + resourceId + '/mode/2/start',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Basic XXX'
},
body: JSON.stringify({
"cname": "lol",
"uid": "1",
"clientRequest": {
"token": token,
"recordingConfig": {
"maxIdleTime": 30,
"streamTypes": 2,
"channelType": 0,
"videoStreamType": 0,
"transcodingConfig": {
"height": 640,
"width": 360,
"bitrate": 500,
"fps": 15,
"mixedVideoLayout": 1,
"backgroundColor": "#FF0000"
},
"subscribeVideoUids": [
"123",
"456"
],
"subscribeAudioUids": [
"“123”",
"“456”"
],
"subscribeUidGroup": 0
},
"recordingFileConfig": {
"avFileType": [
"hls"
]
},
"storageConfig": {
"accessKey": config.writeAccessKeyId,
"region": 3,
"bucket": config.bucket,
"secretKey": config.writeSecretAccessKey,
"vendor": 1,
"fileNamePrefix": [
"directory1",
"directory2"
]
}
}
})
};
request(options1, function (error, response, body) {
if (error) throw new Error(error);
console.log(response.statusCode);
I referred to the Agora's Cloud Recording API. Authentication and resourceId work fine. The response.statusCode is always 404. Unable to locate the error. I tested on Postman and the URL is not working as well. May I know if any attributes are entered wrongly? Does the user have to join the channel before the recording can start?

In your url, you have specified mode/2/start.
It should be mode/mix/start.
You can refer the documentation here for more information:
https://docs.agora.io/en/cloud-recording/cloud_recording_api_rest?platform=All%20Platforms#parameters-1

Does cloud recording work for Android and iOS as well?

Related

React Native fetch for HTTP2 endpoint can not get body

I use React Native fetch to POST to endpoint which is AWS Lambda. By default it's HTTP/2. That works perfectly fine with curl:
% curl -X POST https://yyyyyy.execute-api.eu-central-1.amazonaws.com/Test/stripe_payment -H "x-api-key: xxxxx"
% {"errorCode": "OK", "client_secret": "zzzz"}
But the same from react native:
try {
response = await fetch(`${API_URL}/stripe_payment`, {
method: 'POST',
headers: {
'x-api-key': API_KEY,
},
});
}
catch (error) {
console.error(error);
}
console.log('API response', response);
Returns only Lambda headers, not body:
API response {"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "dce744f2-6755-47e0-9a9d-74921ae64eba", "offset": 0, "size": 100}}, "_bodyInit": {"_data": {"__collector": [Object], "blobId": "dce744f2-6755-47e0-9a9d-74921ae64eba", "offset": 0, "size": 100}}, "bodyUsed": false, "headers": {"map": {"content-length": "100", "content-type": "application/json", "date": "Fri, 11 Nov 2022 19:33:22 GMT", "x-amz-apigw-id": "bc58SFhsFiAFp1A=", "x-amzn-requestid": "fc157dbb-72d2-459e-a391-1ece0ff9680f", "x-amzn-trace-id": "Root=1-636ea381-0c40c8ec31bb9c4f52d0e44b;Sampled=0"}}, "ok": true, "status": 200, "statusText": "", "type": "default", "url": "https://yyyyyy.execute-api.eu-central-1.amazonaws.com/Test/stripe_payment"}
Above response is correct, but it contains only headers, no body.
I do suspect that is because of HTTP/2 binary protocol, looking at some discussions looks like react native did not support it correctly in the past.
Any hints ?
Thanks,
Mark
ok, looks like i have found the answer: https://github.com/facebook/react-native/issues/24520

React native sending image to server using formdata

I have a problem sending a picture to a server, that's like the default approach, but it does not seem to work.
var source = '/Users/alexx/Library/Developer/CoreSimulator/Devices/44F0FA92-4898-4CFB-862E-4E5EC4C8AB28/data/Containers/Bundle/Application/34BCE695-4B4F-472F-AB5C-F2336AC45273/DoorLock.app/123.jpg';
const form = new FormData();
form.append('image', {
uri: source,
type: 'image/jpg',
name: '123.jpg',
});
const data = () => {
fetch(api ,{
method: 'POST',
body: form,
})
that's the response i get from the server:
{
"_bodyBlob": {
"_data": {
"__collector": [
Object
],
"blobId": "78B18938-15BF-4F18-B3C8-1EB30A24D9F8",
"name": "test.html",
"offset": 0,
"size": 192,
"type": "text/html"
}
},
"_bodyInit": {
"_data": {
"__collector": [
Object
],
"blobId": "78B18938-15BF-4F18-B3C8-1EB30A24D9F8",
"name": "test.html",
"offset": 0,
"size": 192,
"type": "text/html"
}
},
"bodyUsed": false,
"headers": {
"map": {
"connection": "keep-alive",
"content-length": "192",
"content-type": "text/html",
"date": "Mon, 02 Nov 2020 22:57:21 GMT",
"server": "PythonAnywhere"
}
},
"ok": false,
"status": 400,
"statusText": undefined,
"type": "default",
"url": api
}
Although this python code works perfectly and gets a correct response
img = {'file':('123.png', open('the path to the pic/123.png', 'rb'), 'image/png)}
post(api, files = img)
is there any way to get this working or its the server side problem that can't receive the correct arguments?
Adding "file://" to the beginning of the source string fixed the problem.
so the src looks like
var source = 'file:///Users/alexx/Library/Developer/CoreSimulator/Devices/44F0FA92-4898-4CFB-862E-4E5EC4C8AB28/data/Containers/Bundle/Application/34BCE695-4B4F-472F-AB5C-F2336AC45273/DoorLock.app/123.jpg';
then it fetches perfectly, hope it helps anybody who tries to send a local image using formdata, the summary looks like this now
const form = new FormData();
form.append('file', {
uri: source,
name: '123.jpg',
fileName: 'file', //optional
});
fetch(uri,{
method: 'post',
body: form,
})
.then(response => {
console.log("image uploaded")
console.log(response)
})
.catch(console.log);
In Formdata when you pass files, you need to pass 3 parameters where
key expected from the backend (in your case image).
It will be an object which has three properties named name, type, and uri where type is the mime type (ex: image/jpeg).
name of the file
Eg:
data.append("FilePath",{
name:"image.png",
type:"image/png",
uri:"content://com.camera/image.png"
},image.png)

How to get access to user's google calendar from React Native (expo)?

I use Expo, and I want to add access to my app to users which have a Google account. Then I need to get info about Google calendars of the user which login into my app.
I implement login function using: Expo.Google.logInAsync(options) (https://docs.expo.io/versions/latest/sdk/google). My scope look like this:
scopes: ['https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/calendar.readonly']
When someone tries to login into my app, it asks about permission to see calendars list. In response I get:
Object {
"accessToken": "a",
"idToken": "b",
"refreshToken": "c",
"serverAuthCode": "d",
"type": "success",
"user": Object {
"email": "e",
"familyName": "f",
"givenName": "g",
"id": "h",
"name": "i",
"photoUrl": "j",
},
}
I received data about the user, but I don't have any data about its calendars.
I tried to get data about calendars (https://developers.google.com/calendar/v3/reference/calendarList) with this function:
getUsersCalendarList = async (accessToken) => {
let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return calendarsList;
}
In response I got:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"headers": Headers {
"map": Object {
"alt-svc": Array [
"quic=\":443\"; ma=2592000; v=\"44,43,39,35\"",
],
"cache-control": Array [
"public, max-age=0",
],
"content-type": Array [
"application/json; charset=UTF-8",
],
"date": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"expires": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"server": Array [
"GSE",
],
"vary": Array [
"X-Origin",
],
"x-content-type-options": Array [
"nosniff",
],
"x-frame-options": Array [
"SAMEORIGIN",
],
"x-xss-protection": Array [
"1; mode=block",
],
},
},
"ok": false,
"status": 403,
"statusText": undefined,
"type": "default",
"url": "https://www.googleapis.com/calendar/v3/users/me/calendarList",
}
How can I get a list of user's google calendars in Expo?
I find the solution here: React-Native JSON fetch from URL. One needs to use json() function on returned object.
The getUsersCalendarList schulde look like this:
getUsersCalendarList = async (accessToken) => {
let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return calendarsList.json();
}
You can also add the access token as a parameter on the request.
https://www.googleapis.com/calenda/v3/users/me/calendarList?access_token={token}
I am not a react dev so not exactly sure how to fix your header. It looks ok.

React Native use Twitter search API with Application-only authentication

I am new to React Native and want to build an App that uses the Twitter search API to display Tweets. No need for User Authentication.
I've been struggling the last two nights to get this working and starting to get frustrated xD.
I've tried building the request using Fetch and XMLHttpRequest with no luck. Also I tried several packages enabling OAuth 2.0 which also didn't work. I have the feeling I'm over complicating things as all I want to do is use the Application-only authentication and use the Standard search API.
Does anyone out there please have a code snippet on how to do this in react native without any extra packages? Is it possible at all with "just" Fetch or XMLHttpRequest?
Thanks in advance
Edit: Here's my code so far
var base64 = require('base-64');
var credentials = encodeURIComponent(key) + ":" + encodeURIComponent(secret);
var encoded = new Buffer(credentials).toString('base64');
console.log(encoded);
fetch('https://api.twitter.com/oauth2/token', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Basic ' + encoded
},
body: {
'grant_type': 'client_credentials'
},
}).then((response) => console.log(response))
Here the response:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "8dea4e53-7b39-4b78-b1a5-d7ef5a58de48",
"offset": 0,
"size": 114,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "8dea4e53-7b39-4b78-b1a5-d7ef5a58de48",
"offset": 0,
"size": 114,
},
},
"headers": Headers {
"map": Object {
"cache-control": Array [
"public, max-age=0",
],
"content-disposition": Array [
"attachment; filename=json.json",
],
"content-type": Array [
"application/json;charset=utf-8",
],
"date": Array [
"Wed, 16 May 2018 16:55:48 GMT",
],
"expires": Array [
"Tue, 31 Mar 1981 05:00:00 GMT",
],
"last-modified": Array [
"Wed, 16 May 2018 16:55:48 GMT",
],
"ml": Array [
"A",
],
"server": Array [
"tsa_o",
],
"status": Array [
"403 Forbidden",
],
"strict-transport-security": Array [
"max-age=631138519",
],
"x-connection-hash": Array [
"b6dde5b876b934c8dcdb059ef0c400fa",
],
"x-content-type-options": Array [
"nosniff",
],
"x-frame-options": Array [
"DENY",
],
"x-response-time": Array [
"105",
],
"x-transaction": Array [
"0084737c0054c4dc",
],
"x-tsa-request-body-time": Array [
"26",
],
"x-twitter-response-tags": Array [
"BouncerCompliant",
],
"x-ua-compatible": Array [
"IE=edge,chrome=1",
],
"x-xss-protection": Array [
"1; mode=block; report=https://twitter.com/i/xss_report",
],
},
},
"ok": false,
"status": 403,
"statusText": undefined,
"type": "default",
"url": "https://api.twitter.com/oauth2/token",
}
So, I'm happy to report I got this working.
Main problem was the encoding of the Request Body.
Here"s the working code to authenticate and get a bearer token. Then using this token to use the search API:
_getBearer = () => {
var details = {
'grant_type': 'client_credentials'
};
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
var key = "xxx";
var secret = "yyy";
var base64 = require('base-64');
var credentials = encodeURIComponent(key) + ":" + encodeURIComponent(secret);
var encoded = new Buffer(credentials).toString('base64');
console.log("Created encoded credentials: " + encoded);
fetch('https://api.twitter.com/oauth2/token', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Basic ' + encoded
},
body: formBody
}).then((response) => response.json())
.then((responseData) => {
bearerToken = responseData.access_token;
console.log("Got Bearer: " + responseData.access_token);
this._loadTweet();
})
.catch((error) => {
console.error(error);
Alert.alert('Alert Title failure' + JSON.stringify(error))
});
_loadTweet = () => {
console.log("start load tweet");
fetch('https://api.twitter.com/1.1/search/tweets.json?q=love', {
method: 'GET',
headers: {
'Authorization': "Bearer " + bearerToken
}
}).then((response) => response.json())
.then((responseData) => {
console.log(JSON.stringify(responseData));
})
.catch((error) => {
console.error(error);
Alert.alert('Alert Title failure' + JSON.stringify(error))
});
};
};

Restify very simple JSONClient returns empty json

I just started using restify and tries to build a very simple JSONClient and fails on the first step.
var restify = require('restify');
var client = restify.createJsonClient({
url: 'http://api.bgm.tv'
});
client.get('/calendar', function(err, req, res, obj) {
console.log('%j', obj);
});
This pieces of code returns {} with a status code 200
If you check http://api.bgm.tv/calendar in browser or curl it seems to be a legit json GET Rest API and does not require auth or anything else.
I tried other API such as stackoverflow api it works perfectly, so I assume something wrong with the server side?
If anyone can try to run it and help me point out what might went wrong would be very appreciated.
I runned your example node code and got a proper response (the same you get when browsing).
You probably have some version problem or a console.log size limitation.
Try using: console.log(obj[0]); it should print only the first object in the json.
I'm using node v0.8.9 and restify v2.4.1 on a mac.
Yeah, when I use the Postman plugin for Chrome and do a GET request to http://api.bgm.tv/calendar I get:
[
{
"weekday": {
"en": "Mon",
"cn": "星期一",
"ja": "月耀日",
"id": 1
},
"items": [
{
"id": 46458,
"url": "http://bgm.tv/subject/46458",
"type": 0,
"name": "アイカツ! -アイドルカツドウ!-",
"name_cn": "偶像活动",
"summary": "",
"eps": 0,
"air_date": "2012-10-08",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/db/7f/46458_8mM39.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/db/7f/46458_8mM39.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/db/7f/46458_8mM39.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/db/7f/46458_8mM39.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/db/7f/46458_8mM39.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 44,
"on_hold": 0,
"dropped": 0
}
},
{
"id": 57150,
"url": "http://bgm.tv/subject/57150",
"type": 0,
"name": "LINE OFFLINE ~サラリーマン~",
"name_cn": "离线LINE - 上班族 -",
"summary": "",
"eps": 0,
"air_date": "2013-01-07",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/71/28/57150_Kz171.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/71/28/57150_Kz171.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/71/28/57150_Kz171.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/71/28/57150_Kz171.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/71/28/57150_Kz171.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 206,
"on_hold": 0,
"dropped": 0
}
},
{
"id": 58709,
"url": "http://bgm.tv/subject/58709",
"type": 0,
"name": "ハヤテのごとく! Cuties",
"name_cn": "旋风管家 Cuties",
"summary": "",
"eps": 0,
"air_date": "2013-04-08",
"air_weekday": 1,
"images": {
"large": "http://lain.bgm.tv/pic/cover/l/15/28/58709_H7uj8.jpg",
"common": "http://lain.bgm.tv/pic/cover/c/15/28/58709_H7uj8.jpg",
"medium": "http://lain.bgm.tv/pic/cover/m/15/28/58709_H7uj8.jpg",
"small": "http://lain.bgm.tv/pic/cover/s/15/28/58709_H7uj8.jpg",
"grid": "http://lain.bgm.tv/pic/cover/g/15/28/58709_H7uj8.jpg"
},
"collection": {
"wish": 0,
"collect": 0,
"doing": 219,
"on_hold": 0,
"dropped": 0
}
},
...and a bunch more, but the body limit to answers on SO is 30,000 characters.