Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
        }