Beispiel #1
0
        private ImageResponse UploadToApn(string Filepath, Model.AccountAppDotNet account)
        {
            string delegateClientIdOfImgLy = "XaBgfNdXRL6msTWhewgVaMB3BumT22YQ";

            if (File.Exists(Filepath))
            {
                // Read file data
                FileStream fs   = new FileStream(Filepath, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                Dictionary <string, string> oauthParams = new Dictionary <string, string>();
                oauthParams.Add("grant_type", "delegate");
                oauthParams.Add("delegate_client_id", delegateClientIdOfImgLy);

                Dictionary <string, string> oAuthHeaders = new Dictionary <string, string>();
                oAuthHeaders.Add("Authorization", "Bearer " + account.accessToken);

                WebHelpers.Response oAuthResponse = WebHelpers.SendPostRequest("https://alpha.app.net/oauth/access_token", oauthParams, additionalHeaders: oAuthHeaders);

                oAuthDelegateToken oAuthToken = JsonConvert.DeserializeObject <oAuthDelegateToken>(oAuthResponse.Content);
                if (oAuthToken == null)
                {
                    return(null);
                }



                // Generate post objects
                Dictionary <string, object> postParameters    = new Dictionary <string, object>();
                Dictionary <string, string> additionalHeaders = new Dictionary <string, string>();

                additionalHeaders.Add("Identity-Delegate-Token", oAuthToken.delegate_token);
                additionalHeaders.Add("Identity-Delegate-Endpoint", "https://alpha-api.app.net/stream/0/token");

                postParameters.Add("media", data);



                // Create request and receive response
                HttpWebResponse webResponse = WebHelpers.MultipartFormDataPost("http://img.ly/api/2/upload.json", postParameters, null, additionalHeaders);

                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                string       fullResponse   = responseReader.ReadToEnd();
                webResponse.Close();
                return(parseResponse(fullResponse));
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
 public bool ValidateCredentials()
 {
     WebHelpers.Response respone = WebHelpers.SendGetRequest(string.Format("https://api.bitly.com/v3/validate/?x_login=notLogin&x_apiKey=not_apikey&apiKey={1}&login={0}&format=txt", Login, Password));
     if (respone.Success)
     {
         if (respone.Content.Trim() == "0")
         {
             return(true);
         }
     }
     return(false);;
 }