我需要GoogleFit REST API中的帮助

时间:2019-07-15 05:04:03

标签: ios google-fit

当我调用此Api然后出现错误时。 https://www.googleapis.com/fitness/v1/users/(AppDelegate.User_Id)/dataSources

以下是我的代码

async contact_detail: contactId => {
    return rp({
       url: 'myapiurl2',
       qs: { ... }
    })
      .then( body => JSON.parse(body))
      .catch( error => { 
         console.log(error);
         //This will return undefined in exception cases. You probably dont want to catch here.
      });
};

GoogleFit REST API中发生以下错误。

 var request = URLRequest(url: URL(string: "https://www.googleapis.com/fitness/v1/users/\(AppDelegate.User_Id)/dataSources")!)

        request.httpMethod = "POST"
        request.httpBody = try? JSONSerialization.data(withJSONObject: Authentication_Dictionary)
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        request.addValue("application/json", forHTTPHeaderField: "Accept")
        //request.addValue("AIzaSyCf-U_lzqmyIUspLjib6CV8fgSpcfe4k6U", forHTTPHeaderField: "APP_SECRET_KEY")

        let session = URLSession.shared

        let task = session.dataTask(with: request) { data, response, error -> Void in

            if error != nil
            {
                print("error=\(error)")
                return
            }

            // You can print out response object
            //print("response = \(response)")


            do {
                let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary

                if let parseJSON = json {

                    print(json)
                }
            } catch {
                print(error)
            }
        }
        task.resume()

0 个答案:

没有答案