Exemple #1
0
        private async Task <bool> authAsync(Dictionary <string, object> parameters, CancellationTokenSource tokensource = null)
        {
            var header = new Dictionary <string, object>
            {
                { "Referer", "http://www.pixiv.net/" }//header
            };
            var api = "https://oauth.secure.pixiv.net/auth/token";//oauth_url

            Task <HttpResponseMessage> taskpost;


            taskpost = HttpPostAsync(api, header, parameters, tokensource);

            HttpResponseMessage result = null;

            try
            {
                result = await taskpost;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (!result.IsSuccessStatusCode)
            {
                Debug.WriteLine(result);
                return(false);
            }


            var json = JObject.Parse(result.Content.ReadAsStringAsync().Result);

            user        = new pixivUser();
            user.avatar = new string[3];

            var response = json.Value <JObject>("response");

            user.access_token  = response["access_token"].ToString();
            user.expires_time  = (int)response["expires_in"];
            user.refresh_token = response["refresh_token"].ToString();
            user.id            = response["user"]["id"].ToString();
            user.name          = response["user"]["name"].ToString();
            user.avatar[0]     = response["user"]["profile_image_urls"]["px_16x16"].ToString();   //0 small
            user.avatar[1]     = response["user"]["profile_image_urls"]["px_50x50"].ToString();   //1 middle
            user.avatar[2]     = response["user"]["profile_image_urls"]["px_170x170"].ToString(); //2 big
            return(true);
        }
Exemple #2
0
        private async Task<bool> authAsync(Dictionary<string, object> parameters, CancellationTokenSource tokensource = null)
        {
            var header = new Dictionary<string, object>
            {
                {"Referer","http://www.pixiv.net/" }//header
            };
            var api = "https://oauth.secure.pixiv.net/auth/token";//oauth_url

            Task<HttpResponseMessage> taskpost;


            taskpost = HttpPostAsync(api, header, parameters, tokensource);

            HttpResponseMessage result = null;

            try
            {
                result = await taskpost;
            }
            catch(Exception ex)
            {
                throw ex;
            }

            if (!result.IsSuccessStatusCode)
            {
                Debug.WriteLine(result);
                return false;
            }


            var json = JObject.Parse(result.Content.ReadAsStringAsync().Result);

            user = new pixivUser();
            user.avatar = new string[3];

            var response = json.Value<JObject>("response");

            user.access_token = response["access_token"].ToString();
            user.expires_time = (int)response["expires_in"];
            user.refresh_token = response["refresh_token"].ToString();
            user.id = response["user"]["id"].ToString();
            user.name = response["user"]["name"].ToString();
            user.avatar[0] = response["user"]["profile_image_urls"]["px_16x16"].ToString();//0 small
            user.avatar[1] = response["user"]["profile_image_urls"]["px_50x50"].ToString();//1 middle
            user.avatar[2] = response["user"]["profile_image_urls"]["px_170x170"].ToString();//2 big
            return true;
        }