Exemplo n.º 1
0
 /// <summary>
 /// 构造函数,初始化访问环境
 /// </summary>
 /// <param name="consumerKey"></param>
 /// <param name="consumerSecret"></param>
 /// <param name="oAuthToken"></param>
 /// <param name="oAuthTokenSecret"></param>
 /// <param name="authorized_verifier"></param>
 /// <param name="isApi"></param>
 /// <param name="openId"></param>
 public Qzone(string consumerKey, 
     string consumerSecret,
     string oAuthToken, 
     string oAuthTokenSecret, 
     string authorized_verifier,
     bool isApi =false,string openId = "")
 {
     if (string.IsNullOrEmpty(consumerKey) || string.IsNullOrEmpty(consumerSecret) || string.IsNullOrEmpty(oAuthToken)
         || string.IsNullOrEmpty(oAuthTokenSecret))
     {
         throw new ArgumentNullException("参数consumerKey、consumerSecret、oAuthToken、oAuthTokenSecret不能为空");
     }
     if (isApi)
     {
         if (string.IsNullOrEmpty(openId))
         {
             throw new ArgumentNullException("访问Qzone的api要求带获取到的token(access token)、token secret(access token secret)、openid。");
         }
     }
     if (!isApi)
     {
         QzoneContext context = new QzoneContext(consumerKey, consumerSecret);
         var accessToken = context.GetAccessToken(oAuthToken, oAuthTokenSecret, authorized_verifier);
         context.OAuthTokenKey = accessToken.TokenKey;
         context.OAuthTokenSecret = accessToken.TokenSecret;
         Init(accessToken.TokenKey, accessToken.TokenSecret, accessToken.Openid, context);
     }
     else
     {
         QzoneContext context = new QzoneContext(consumerKey, consumerSecret, oAuthToken, oAuthTokenSecret, openId);
         Init(oAuthToken, oAuthTokenSecret, openId, context);
     }
 }