errorCode = 300 message = "Api key and secret are required."


#1

While using Rest API “https://api.zoom.us/v1/user/getbyemail”. getting error:
error = {
code = 300;
message = “Api key and secret are required.”;
};

Request Param for API :
{“api_key”: “hRJiOsC-Swm_BqGmBIxV4w”, “data_type”: “JSON”, “api_secret”: “930qZd2qDb6UptAGxXfhAyNoBl5oXtV1pnY5”, “email”: “<email_id>”, “login_type”: 100}

I am using above API with IOS(swift) to fetch user detail. Below are my code:

import Foundation

typealias ZoomAuthResponse = (_ status: Bool, _ error: Int) -> Void
typealias ZoomUserResponse = (_ status: Bool, _ user : ZoomUser?, _ error: Int) -> Void

let kZoomSDKAppKey = “fzdxp0KDUdXjnz8LrnqVzeR109vY1926VvO4”
let kZoomSDKAppSecret = “RjKE6YFpgeJT3aBIBuv5ZSspATJCMafbWLmH”
let kZoomSDKDomain = “zoom.us
let kZoomADKAPIkey = “hRJiOsC-Swm_BqGmBIxV4w”
let kZoomADKAPISecretkey = “930qZd2qDb6UptAGxXfhAyNoBl5oXtV1pnY5”

struct ZoomNetworkConstants {
let getUserByemail = “https://api.zoom.us/v1/user/getbyemail

struct userRequestKeys {
let email = “email”
let type = “login_type”
let apiKey = “api_key”
let apiSecret = “api_secret”
let dataType = “data_type”
}

}

// MARK:- Login / Session Information
struct ZoomUser {
private struct JSONKeys { //
let userid = “id”
let email = “email”
let firstName = “first_name”
let lastName = “last_name”
let picUrl = “pic_url”
let type = “type”
let meetNumber = “pmi”
let token = “token”

let timeZone = “timezone”
let createdAt = “created_at”
let lastClientVersion = “lastClientVersion”
let lastLoginTime = “lastLoginTime”
}
var userFirstName: String?
var userLastName: String?
var email: String?
var userZoomId: String?
var userTocken: String?
var userMeetNumber: Int?
var userParticipantID: String?
var userWebinarToken: String?
var userType: Int?

init() {
userFirstName = “”
userLastName = “”
userZoomId = “”
email = “”
userTocken = “”
userMeetNumber = 0
userParticipantID = “”
userWebinarToken = “”
userType = -1
}

init(json : [String : Any]) {
userFirstName = json[JSONKeys().firstName] as? String ?? “”
userLastName = json[JSONKeys().lastName] as? String ?? “”
userZoomId = json[JSONKeys().userid] as? String ?? “”
userTocken = json[JSONKeys().token] as? String ?? “”
userMeetNumber = json[JSONKeys().meetNumber] as? Int ?? 0
userParticipantID = “”
userWebinarToken = “”
userType = json[JSONKeys().type] as? Int ?? -1
}
}

class ZoomAuth: NSObject {

fileprivate var complitionHandler : ZoomAuthResponse?

var user : ZoomUser? = ZoomUser()
static let shared = ZoomAuth()
fileprivate var email: String?
func getZoomAuthService() -> MobileRTCAuthService? {
let authService = MobileRTC.shared().getAuthService()
MobileRTC.shared().mobileRTCDomain = kZoomSDKDomain
authService?.delegate = self
return authService
}

func sdkAuth(completionHandler: @escaping ZoomAuthResponse) {
let authService = MobileRTC.shared().getAuthService()
self.complitionHandler = completionHandler
if authService != nil {
authService?.clientKey = kZoomSDKAppKey
authService?.clientSecret = kZoomSDKAppSecret
authService?.sdkAuth()
} else {
complitionHandler?(false, Int(MobileRTCAuthError_Unknown.rawValue))
}
}

func zoomLogin(email:String, password:String, completionHandler: @escaping ZoomAuthResponse) {
let authService = MobileRTC.shared().getAuthService()
self.email = email
authService?.delegate = self
self.complitionHandler = completionHandler
if authService != nil {
authService?.login(withEmail: email, password: password)
} else {
complitionHandler?(false, Int(MobileRTCAuthError_Unknown.rawValue))
}
}

func fetchLoginUserDetail(email: String, type:Int, completionHandler: @escaping ZoomUserResponse) {
do {
let request = NSMutableURLRequest(url: URL(string: ZoomNetworkConstants().getUserByemail)!)

let session = URLSession.shared
request.httpMethod = “POST”

//Note : Add the corresponding “Content-Type” and “Accept” header. In this example I had used the application/json.
request.addValue(“application/json”, forHTTPHeaderField: “Content-Type”)
request.addValue(“application/json”, forHTTPHeaderField: “Accept”)

let parameters = [ZoomNetworkConstants.userRequestKeys().apiKey: kZoomADKAPIkey, ZoomNetworkConstants.userRequestKeys().apiSecret: kZoomADKAPISecretkey, ZoomNetworkConstants.userRequestKeys().dataType: “JSON”, ZoomNetworkConstants.userRequestKeys().email: email, ZoomNetworkConstants.userRequestKeys().type: MobileRTCUserType_ZoomUser.rawValue] as [String : Any]
request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: )

let task = session.dataTask(with: request as URLRequest) { data, response, error in
guard data != nil else {
print(“no data found: (error ?? “” as! Error)”)
return
}

do {
if let json = try JSONSerialization.jsonObject(with: data!, options: ) as? NSDictionary {
print(“Response: (json)”)
let user = ZoomUser(json: (json as? [String : Any] ?? String : Any))
completionHandler(true, user, 0)
} else {
let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)// No error thrown, but not NSDictionary
print(“Error could not parse JSON: (jsonStr ?? “”)”)
completionHandler(false, nil, 1)
}
} catch let parseError {
print(parseError)// Log the error thrown by JSONObjectWithData
let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print(“Error could not parse JSON: ‘(jsonStr ?? “”)’”)
completionHandler(false, nil, 1)

}
}

task.resume()
} catch let erorr {
print(erorr)
}
}

}

extension ZoomAuth : MobileRTCAuthDelegate {

func onMobileRTCAuthReturn(_ returnValue: MobileRTCAuthError) {
let status = ((returnValue == MobileRTCAuthError_Success) ? true : false)
self.complitionHandler?(status, Int(returnValue.rawValue))
}

func onMobileRTCLoginReturn(_ returnValue: Int) {
var loginStatus = ((returnValue == 0) ? true : false)
if loginStatus {
self.fetchLoginUserDetail(email: self.email ?? “”, type: 100 , completionHandler: { (status, user, error) in
loginStatus = ((error == 0) ? true : false)
self.user = user
self.complitionHandler?(status, error)
})
} else {
self.complitionHandler?(loginStatus, returnValue)
}
}
}


#2

Hi Nilesh,

after you changed to running on main thread, did it solve the issue?


#3

No, This issue is still occurs even I move my code on main thread.


#4

Hi Nilesh,

please check again on how you pass API key and secret to query params.

Best


#5

Hi,

I cross check all params. Please find below request Params:

{“api_key”: “VfswOhRjTfiW5EESVkmaOQ”, “data_type”: “JSON”, “api_secret”: “f6xttFzp2MLbivkHKaxujmgJ3o1iJpr5M0Oj”, “email”: “<email_id>”, “login_type”: 100}

 


#6

As per zoom team suggestion :

pass the parameters as below:
https://api.zoom.us/v1/user/getbyemail?api_key=xxx&api_secret=xxx&

It works for me.