我正在尝试使用fitbit API设置迷你游戏。我需要获取游戏操作的一些用户数据。我不是100%如何访问它们。这是我目前的尝试,但不起作用。我试图关注这个帖子https://groups.google.com/d/msg/fitbit-api/n0yv3-dzAqY/8y6old2EItQJ。如果我离开或者有更好的主意,请告诉我。这是进入未知的领域。我得到这个工作后会发布完成的应用程序。
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import org.iotashan.oauth.IOAuthSignatureMethod;
import org.iotashan.oauth.OAuthConsumer;
import org.iotashan.oauth.OAuthRequest;
import org.iotashan.oauth.OAuthSignatureMethod_HMAC_SHA1;
import org.iotashan.oauth.OAuthToken;
public class Fitbit extends Sprite
{
private static var CONSUMER_SECRET:String = "xxxxxxxxxx";
private static var CONSUMER_KEY:String = "xxxxxxxxxx";
private static var REQUEST_TOKEN_URL:String = "http://api.fitbit.com/oauth/request_token";
//private static var REQUEST_TOKEN_URL:String = "https://www.fitbit.com/oauth/authorize?oauth_token=";
private static var ACCESS_TOKEN_URL:String = "http://api.fitbit.com/oauth/access_token";
private static var AUTHORIZE_URL:String = "http://www.fitbit.com/oauth/authorize";
private static var API_URL:String = "http://api.fitbit.com";
private static var SIGNATURE:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
public function Fitbit()
{
var consumer:OAuthConsumer = new OAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET);
var token:OAuthToken = new OAuthToken(CONSUMER_KEY,CONSUMER_SECRET);
var mainRequest:OAuthRequest = new OAuthRequest(URLRequestMethod.GET,API_URL+'/1/user/2FV43Z/profile.json',null,consumer,token);
var getDataHead:URLRequestHeader = mainRequest.buildRequest(SIGNATURE, "header", API_URL);
var getDataURL:URLRequest = new URLRequest(API_URL+'/1/user/2FV43Z/profile.json');
getDataURL.requestHeaders.push(getDataHead);
var getDataLoader:URLLoader = new URLLoader();
getDataLoader.load(getDataURL);
getDataLoader.addEventListener(Event.COMPLETE,onLoadComplete);
getDataLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
}
public function onError(e:IOErrorEvent):void {
trace(e.currentTarget.data);
1+1;
}
public function onLoadComplete(e:Event):void {
trace("FINISHED");
1+1;
}
}
}