GetDataResponseAsync() public static méthode

Gets a data response for the given base url and parameters, either using OAuth or not depending on which parameters were passed in.
public static GetDataResponseAsync ( Twitter flickr, string method, string baseUrl, string>.Dictionary parameters ) : Task>
flickr Twitter The current instance of the class.
method string
baseUrl string The base url to be called.
parameters string>.Dictionary A dictionary of parameters.
Résultat Task>
        /// <summary>
        /// Get an <see cref="OAuthRequestToken"/> for the given callback URL.
        /// </summary>
        /// <remarks>Specify 'oob' as the callback url for no callback to be performed.</remarks>
        /// <param name="callbackUrl">The callback Uri, or 'oob' if no callback is to be performed.</param>
        /// <param name="callback"></param>
        public async Task <FlickrResult <OAuthRequestToken> > OAuthGetRequestTokenAsync(string callbackUrl)
        {
            string url = RequestTokenUrl; //"https://www.flickr.com/services/oauth/request_token";

            Dictionary <string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_callback", callbackUrl);

            string sig = OAuthCalculateSignature("POST", url, parameters, null);

            parameters.Add("oauth_signature", sig);

            FlickrResult <string> r = await TwitterResponder.GetDataResponseAsync(this, "POST", url, parameters);

            FlickrResult <OAuthRequestToken> result = new FlickrResult <OAuthRequestToken>();

            if (!r.HasError)
            {
                result.Result = FlickrNet.OAuthRequestToken.ParseResponse(r.Result);
            }
            else
            {
                result.HasError     = r.HasError;
                result.Error        = r.Error;
                result.ErrorCode    = r.ErrorCode;
                result.ErrorMessage = r.ErrorMessage;
            }

            return(result);
        }
        /// <summary>
        /// For a given request token and verifier string return an access token.
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <param name="verifier"></param>
        /// <param name="callback"></param>
        public async Task <FlickrResult <OAuthAccessToken> > OAuthGetAccessTokenAsync(string requestToken, string requestTokenSecret, string verifier)
        {
            string url = "https://api.twitter.com/oauth/access_token";

            Dictionary <string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_verifier", verifier);
            parameters.Add("oauth_token", requestToken);

            string sig = OAuthCalculateSignature("POST", url, parameters, requestTokenSecret);

            parameters.Add("oauth_signature", sig);

            FlickrResult <string> r = await TwitterResponder.GetDataResponseAsync(this, "POST", url, parameters);

            FlickrResult <OAuthAccessToken> result = new FlickrResult <OAuthAccessToken>();

            if (!r.HasError)
            {
                result.Result = FlickrNet.OAuthAccessToken.ParseResponse(r.Result);
            }
            else
            {
                result.HasError     = r.HasError;
                result.Error        = r.Error;
                result.ErrorCode    = r.ErrorCode;
                result.ErrorMessage = r.ErrorMessage;
            }

            return(result);
        }
Exemple #3
0
        private async Task <FlickrResult <T> > GetResponseAsync <T>(Dictionary <string, string> parameters, string method) where T : IFlickrParsable, new()
        {
            CheckApiKey();

            parameters["api_key"] = ApiKey;

            if (!String.IsNullOrEmpty(OAuthAccessToken) || String.IsNullOrEmpty(AuthToken))
            {
                OAuthGetBasicParameters(parameters);
                parameters.Remove("api_key");
                if (!String.IsNullOrEmpty(OAuthAccessToken))
                {
                    parameters["oauth_token"] = OAuthAccessToken;
                }
            }
            else
            {
                parameters["auth_token"] = AuthToken;
            }

            Uri url;

            //if (!String.IsNullOrEmpty(sharedSecret))
            //    url = CalculateUri(parameters, true);
            //else
            url = CalculateUri(parameters, false);

            lastRequest = url.AbsoluteUri;



            FlickrResult <string> r = await TwitterResponder.GetDataResponseAsync(this, method, url.AbsoluteUri, parameters);

            FlickrResult <T> result = new FlickrResult <T>();

            if (!r.HasError)
            {
                lastResponse = r.Result;
                using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(r.Result)))
                {
                    try
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                        T t = (T)serializer.ReadObject(ms);
                        result.Result   = t;
                        result.HasError = false;
                    }
                    catch (Exception ex)
                    {
                        result.HasError = true;
                        result.Error    = ex;
                    }
                }
            }
            else
            {
                result.HasError     = true;
                result.ErrorCode    = r.ErrorCode;
                result.ErrorMessage = r.ErrorMessage;
                result.Error        = r.Error;
            }


            return(result);
        }