0
var appCredentials = new FitbitAppCredentials()
{
ClientId = "227RD5", //ConfigurationManager.AppSettings["FitbitClientId"],
ClientSecret = "468c585ba98fc84e463952ca7a306c07" //ConfigurationManager.AppSettings["FitbitClientSecret"]
};
string UserId = Convert.ToBase64String((Encoding.ASCII.GetBytes("3J9685")));
string code = Request.Params["code"];
StringBuilder dataRequestUrl = new StringBuilder();
dataRequestUrl.Append("https://api.fitbit.com/1/user/-");
dataRequestUrl.Append("/profile.json");
HttpWebRequest dataRequest = (HttpWebRequest)WebRequest.Create(dataRequestUrl.ToString());
dataRequest.Method = "POST";
string _auth = string.Format("{0}:{1}", appCredentials.ClientId, appCredentials.ClientSecret);
var _encbyte = Encoding.ASCII.GetBytes(_auth);
string _enc = Convert.ToBase64String(_encbyte);
string _authorizationHeader = string.Format("{0} {1}", "Bearer", _enc);
dataRequest.Headers["Authorization"] = _authorizationHeader;
dataRequest.ContentType = "application/x-www-form-urlencoded";
dataRequest.Accept = "application/json";
string responseJson;
HttpWebResponse response = null;
try
{
response = dataRequest.GetResponse() as HttpWebResponse;
}
catch (WebException webEx)
{
response = webEx.Response as HttpWebResponse;
}
catch (Exception ex)
{
throw ex;
}
using (var reader = new StreamReader(response.GetResponseStream()))
{
responseJson = reader.ReadToEnd();
}
위의 코드는 권한이없는 액세스 오류를 발생시킵니다. 어느 누구든지 코드에서 문제가 무엇인지 알 수 있습니다. 사용자 권한을 부여하고 사용자 토큰을 새로 고칠 수 있지만 userprofile.json 호출을 시도하면 권한이없는 액세스 오류가 발생합니다.Fitbit Oauth2.0 API - 사용자 프로필 데이터 얻기
사용 http://stackoverflow.com/questions/37520816/how-to-integrate-fitbit-api-in-ios-app-using-swift/39697291 # 39697291 –