コード例 #1
0
        public string GetUserInfo(string oAuthToken, string oAuthTokenSecret, string format, string fields)
        {
            OAuthBase oAuth = new OAuthBase();
            string accessTokenUrl = string.Format("http://{0}/v2/people/@me/@self", ApiDomain);
            string timestamp = oAuth.GenerateTimeStamp();
            string nonce = oAuth.GenerateNonce();

            List<QueryParameter> parameters = new List<QueryParameter>();
            parameters.Add(new QueryParameter("fields", fields));
            parameters.Add(new QueryParameter("format", format));

            string signature = oAuth.GenerateSignature(
                new Uri(accessTokenUrl),
                ConsumerKey,
                ConsumerSecret,
                oAuthToken,
                oAuthTokenSecret,
                "GET",
                timestamp,
                nonce,
                SignatureTypes.HMACSHA1,
                parameters);

            string accessQueryParametersFormat = "{0}?fields={1}&format={2}&oauth_consumer_key={3}&oauth_nonce={4}&oauth_signature={5}&oauth_signature_method={6}&oauth_timestamp={7}&oauth_token={8}&oauth_version={9}";
            string generatedAccessTokenUrl = string.Format(
                accessQueryParametersFormat,
                accessTokenUrl,
                OAuthBase.UrlEncode(fields),
                OAuthBase.UrlEncode(format),
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode(signature),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("1.0"));

            return HttpGet(generatedAccessTokenUrl);
        }
コード例 #2
0
        public OAuthTuple GetAccessToken(string oAuthToken, string oAuthTokenSecret)
        {
            OAuthBase oAuth = new OAuthBase();
            string accessTokenUrl = string.Format("http://{0}/access_token", ApiDomain);
            string timestamp = oAuth.GenerateTimeStamp();
            string nonce = oAuth.GenerateNonce();

            string signatureAccess = oAuth.GenerateSignature(
                new Uri(accessTokenUrl),
                ConsumerKey,
                ConsumerSecret,
                oAuthToken,
                oAuthTokenSecret,
                "GET",
                timestamp,
                nonce,
                SignatureTypes.HMACSHA1);

            string accessQueryParametersFormat = "{0}?oauth_consumer_key={1}&oauth_token={2}&oauth_signature_method={3}&oauth_signature={4}&oauth_timestamp={5}&oauth_nonce={6}&oauth_version={7}";
            string generatedAccessTokenUrl = string.Format(
                accessQueryParametersFormat,
                accessTokenUrl,
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(signatureAccess),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode("1.0"));

            string accessTokenReturn = HttpGet(generatedAccessTokenUrl);
            return Util.ParseQueryString(accessTokenReturn);
        }
コード例 #3
0
        public OAuthTuple GetRequestToken()
        {
            string requestTokenUrl = string.Format("http://{0}/request_token", ApiDomain);
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timestamp = oAuth.GenerateTimeStamp();

            string signature =
                oAuth.GenerateSignature(
                        new Uri(requestTokenUrl),
                        ConsumerKey,
                        ConsumerSecret,
                        "",
                        "",
                        "GET",
                        timestamp,
                        nonce,
                        SignatureTypes.HMACSHA1);

            string requestTokenUrlFormat = "{0}?oauth_consumer_key={1}&oauth_nonce={2}&oauth_signature={3}&oauth_signature_method={4}&oauth_timestamp={5}&oauth_token={6}&oauth_version={7}";
            string generatedRequestTokenUrl = string.Format(
                requestTokenUrlFormat,
                requestTokenUrl,
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode(signature),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(""),
                OAuthBase.UrlEncode("1.0"));

            string requestToken = HttpGet(generatedRequestTokenUrl);
            return Util.ParseQueryString(requestToken);
        }
コード例 #4
0
        public string PostNotifications(string oAuthToken, long applicationId, string templateId, IDictionary<string, string> templateParameters, string culture, string format)
        {
            string templateParametersString = Util.DictionaryToJson(templateParameters);
            string requestTokenUrl = string.Format("http://{0}/v1/applications/{1}/notifications", ApiDomain, applicationId);

            Uri uri = new Uri(requestTokenUrl);
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timestamp = oAuth.GenerateTimeStamp();

            List<QueryParameter> parameters = new List<QueryParameter>();
            parameters.Add(new QueryParameter("culture", culture));
            parameters.Add(new QueryParameter("format", format));
            parameters.Add(new QueryParameter("templateId", templateId));
            parameters.Add(new QueryParameter("templateParameters", templateParametersString));

            string signature =
                oAuth.GenerateSignature(
                        uri,
                        ConsumerKey,
                        ConsumerSecret,
                        oAuthToken,
                        "",
                        "POST",
                        timestamp,
                        nonce,
                        SignatureTypes.HMACSHA1,
                        parameters);

            string requestTokenUrlFormat = "{0}?culture={1}&format={2}&oauth_consumer_key={3}&oauth_nonce={4}&oauth_signature_method={5}&oauth_timestamp={6}&oauth_token={7}&oauth_version={8}&oauth_signature={9}";

            string generatedUrl = string.Format(
                requestTokenUrlFormat,
                requestTokenUrl,
                culture,
                format,
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("1.0"),
                OAuthBase.UrlEncode(signature));

            string message = GenerateTemplateActivityBody(templateId, OAuthBase.UrlEncode(templateParametersString));
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] requestData = encoding.GetBytes(message);

            var response = HttpPost(generatedUrl, requestData);
            return response;
        }
コード例 #5
0
        public PostActivityFeedResult PostActivityFeed(string oAuthToken, string templateId, IDictionary<string, string> templateParameters, IList<string> mediaItems, string culture, string format)
        {
            string templateParametersString = Util.DictionaryToJson(templateParameters);
            string mediaItemsString = Util.ListToJson(mediaItems);
            string requestTokenUrl = string.Format("http://{0}/v2/activities/@me/@self", ApiDomain);

            Uri uri = new Uri(requestTokenUrl);
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timestamp = oAuth.GenerateTimeStamp();
            List<QueryParameter> parameters = new List<QueryParameter>();
            parameters.Add(new QueryParameter("culture", culture));
            parameters.Add(new QueryParameter("format", format));
            parameters.Add(new QueryParameter("templateId", templateId));
            parameters.Add(new QueryParameter("templateParameters", templateParametersString));
            parameters.Add(new QueryParameter("mediaItems", mediaItemsString));

            string signature =
                oAuth.GenerateSignature(
                        uri,
                        ConsumerKey,
                        ConsumerSecret,
                        oAuthToken,
                        "",
                        "POST",
                        timestamp,
                        nonce,
                        SignatureTypes.HMACSHA1,
                        parameters);

            string requestTokenUrlFormat = "http://{0}/v2/activities/@me/@self?culture={1}&format={2}&oauth_consumer_key={3}&oauth_nonce={4}&oauth_signature_method={5}&oauth_timestamp={6}&oauth_token={7}&oauth_version={8}&oauth_signature={9}";

            string generatedUrl = string.Format(
                requestTokenUrlFormat,
                ApiDomain,
                culture,
                format,
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("1.0"),
                OAuthBase.UrlEncode(signature));

            string message = GenerateTemplateActivityBody(templateId, OAuthBase.UrlEncode(templateParametersString), OAuthBase.UrlEncode(mediaItemsString));
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] requestData = encoding.GetBytes(message);

            var response = HttpPost(generatedUrl, requestData);
            var postActivityFeedResult = (PostActivityFeedResult)JsonConvert.Import(typeof(PostActivityFeedResult), response);
            return postActivityFeedResult;
        }
コード例 #6
0
        public PersonInfo GetMySpaceInfo(string oAuthToken, string oAuthTokenSecret)
        {
            OAuthBase oAuth = new OAuthBase();
            string url = string.Format("http://{0}/v1/user.json", ApiDomain);
            string timestamp = oAuth.GenerateTimeStamp();
            string nonce = oAuth.GenerateNonce();

            string signatureAccess = oAuth.GenerateSignature(
                new Uri(url),
                ConsumerKey,
                ConsumerSecret,
                oAuthToken,
                oAuthTokenSecret,
                "GET",
                timestamp,
                nonce,
                SignatureTypes.HMACSHA1);

            string queryParametersFormat = "{0}?oauth_consumer_key={1}&oauth_token={2}&oauth_signature_method={3}&oauth_signature={4}&oauth_timestamp={5}&oauth_nonce={6}&oauth_version={7}";

            string generatedUrl = string.Format(
                queryParametersFormat,
                url,
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(signatureAccess),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode("1.0"));

            var response = HttpGet(generatedUrl);
            var personInfoResult = (PersonInfo)JsonConvert.Import(typeof(PersonInfo), response);
            return personInfoResult;
        }
コード例 #7
0
        public ExtendedProfile GetMySpaceExtendedProfile(string oAuthToken, string oAuthTokenSecret, long userId)
        {
            OAuthBase oAuth = new OAuthBase();
            string url = string.Format("http://{0}/v1/users/{1}/profile.json", ApiDomain, userId);
            string timestamp = oAuth.GenerateTimeStamp();
            string nonce = oAuth.GenerateNonce();

            List<QueryParameter> parameters = new List<QueryParameter>();
            parameters.Add(new QueryParameter("detailtype", "extended"));

            string signatureAccess = oAuth.GenerateSignature(
                new Uri(url),
                ConsumerKey,
                ConsumerSecret,
                oAuthToken,
                oAuthTokenSecret,
                "GET",
                timestamp,
                nonce,
                SignatureTypes.HMACSHA1,
                parameters);

            string queryParametersFormat = "{0}?detailtype={1}&oauth_consumer_key={2}&oauth_token={3}&oauth_signature_method={4}&oauth_signature={5}&oauth_timestamp={6}&oauth_nonce={7}&oauth_version={8}";

            string generatedUrl = string.Format(
                queryParametersFormat,
                url,
                OAuthBase.UrlEncode("extended"),
                OAuthBase.UrlEncode(ConsumerKey),
                OAuthBase.UrlEncode(oAuthToken),
                OAuthBase.UrlEncode("HMAC-SHA1"),
                OAuthBase.UrlEncode(signatureAccess),
                OAuthBase.UrlEncode(timestamp),
                OAuthBase.UrlEncode(nonce),
                OAuthBase.UrlEncode("1.0"));

            var response = HttpGet(generatedUrl);
            var extendedProfile = (ExtendedProfile)JsonConvert.Import(typeof(ExtendedProfile), response);
            return extendedProfile;
        }