예제 #1
0
        private static void AddSDLandTLDParameters(string hostname, QuerystringParameters querystringParameters)
        {
            var pieces = PartsOfDNSRecord.ExtractFromHostname(hostname);

            querystringParameters.Add("SLD", pieces.SecondLevelDomain);
            querystringParameters.Add("TLD", pieces.TopLevelDomain);
        }
예제 #2
0
        public static APITestUser CreateUser(string accessToken, string applicationId, string userFullname)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("installed", "true");
            parameters.Add("name", userFullname);
            parameters.Add("permissions", "read_stream");
            parameters.Add("method", "post");
            parameters.Add("access_token", accessToken);

            string url = "https://graph.facebook.com/" + applicationId + "/accounts/test-users?" +
                                    parameters.AsQuerystring();

            var response = DownloadString(new Uri(url));

            return JsonConvert.DeserializeObject<APITestUser>(response);
        }
예제 #3
0
        public static APITestUser CreateUser(string accessToken, string applicationId, string userFullname)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("installed", "true");
            parameters.Add("name", userFullname);
            parameters.Add("permissions", "read_stream");
            parameters.Add("method", "post");
            parameters.Add("access_token", accessToken);

            string url = "https://graph.facebook.com/" + applicationId + "/accounts/test-users?" +
                         parameters.AsQuerystring();

            var response = DownloadString(new Uri(url));

            return(JsonConvert.DeserializeObject <APITestUser>(response));
        }
예제 #4
0
        public static string GetAppToken(string applicationId, string applicationSecret)
        {
            QuerystringParameters parameters = new QuerystringParameters();

            parameters.Add("client_id", applicationId);
            parameters.Add("client_secret", applicationSecret);
            parameters.Add("grant_type", "client_credentials");

            var uri = "https://graph.facebook.com/oauth/access_token?" + parameters.AsQuerystring();

            var result = DownloadString(uri);

            string prefix = "access_token=";
            if (!result.StartsWith(prefix))
                throw new Exception("Unexpected response creating access token - expected prefix 'access_token=', actually started with " + result.Take(20));

            return result.Substring(prefix.Length);
        }
예제 #5
0
        public static string GetAppToken(string applicationId, string applicationSecret)
        {
            QuerystringParameters parameters = new QuerystringParameters();

            parameters.Add("client_id", applicationId);
            parameters.Add("client_secret", applicationSecret);
            parameters.Add("grant_type", "client_credentials");

            var uri = "https://graph.facebook.com/oauth/access_token?" + parameters.AsQuerystring();

            var result = DownloadString(uri);

            string prefix = "access_token=";

            if (!result.StartsWith(prefix))
            {
                throw new Exception("Unexpected response creating access token - expected prefix 'access_token=', actually started with " + result.Take(20));
            }

            return(result.Substring(prefix.Length));
        }
예제 #6
0
        /// <summary>
        /// Wraps facebook registration script
        /// http://developers.facebook.com/docs/plugins/registration/
        /// </summary>
        /// <param name="onFinishUrl"></param>
        /// <param name="registrationFields">should serialize like the fields parameter passed to facebook's registration url.</param>
        /// <returns></returns>
        public static IHtmlString ShowIframe(
            AppSettingConfig config,
            string onFinishUrl,
            object registrationFields,
            object iframeAttributes)
        {
            var scriptUrlQuerystring = new QuerystringParameters();
            scriptUrlQuerystring.Add("client_id", config.FacebookApplicationId);
            scriptUrlQuerystring.Add("redirect_uri", onFinishUrl);
            scriptUrlQuerystring.Add("fields", Newtonsoft.Json.JsonConvert.SerializeObject(registrationFields));

            var iframe = new XElement("iframe");
            iframe.SetAttributeValue("src", "https://www.facebook.com/plugins/registration.php?" + scriptUrlQuerystring.AsQuerystring());

            foreach (var iframeProperty in iframeAttributes.GetPropertyValues())
            {
                iframe.SetAttributeValue(iframeProperty.Key, iframeProperty.Value);
            }

            return new HtmlString(iframe.ToString());
        }
예제 #7
0
        /// <summary>
        /// I'm not bothering with paging yet, so this only gets some of your test users.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="applicationId"></param>
        /// <returns></returns>
        public static IEnumerable <APITestUser> GetSomeExistingTestUsers(string accessToken, string applicationId)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("access_token", accessToken);

            string url = "https://graph.facebook.com/" + applicationId + "/accounts/test-users?" +
                         parameters.AsQuerystring();

            var response = DownloadString(new Uri(url));

            return(JsonConvert.DeserializeObject <APIUserList>(response).data);
        }
예제 #8
0
        public static void DeleteUser(string accessToken, string userId)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("access_token", accessToken);

            string createUserUri = "https://graph.facebook.com/" + userId +"?" +
                                    parameters.AsQuerystring();

            var response = DownloadString(new Uri(createUserUri), "DELETE");

            if (response != "true")
                throw new Exception("Unable to delete user " + userId + ", response was: " + response);
        }
예제 #9
0
        public static void DeleteUser(string accessToken, string userId)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("access_token", accessToken);

            string createUserUri = "https://graph.facebook.com/" + userId + "?" +
                                   parameters.AsQuerystring();

            var response = DownloadString(new Uri(createUserUri), "DELETE");

            if (response != "true")
            {
                throw new Exception("Unable to delete user " + userId + ", response was: " + response);
            }
        }
예제 #10
0
        /// <summary>
        /// I'm not bothering with paging yet, so this only gets some of your test users.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="applicationId"></param>
        /// <returns></returns>
        public static IEnumerable<APITestUser> GetSomeExistingTestUsers(string accessToken, string applicationId)
        {
            var parameters = new QuerystringParameters();

            parameters.Add("access_token", accessToken);

            string url = "https://graph.facebook.com/" + applicationId + "/accounts/test-users?" +
                                    parameters.AsQuerystring();

            var response = DownloadString(new Uri(url));

            return JsonConvert.DeserializeObject<APIUserList>(response).data;
        }