Ejemplo n.º 1
0
        /// <summary>
        /// Search for media in a given area. The default time span is set to 5 days. The time span must not
        /// exceed 7 days. Defaults time stamps cover the last 5 days. Can return mix of image and video types.
        /// </summary>
        /// <param name="options">The search options.</param>
        public string Search(InstagramRecentMediaSearchOptions options)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken },
                { "lat", options.Latitude.ToString(CultureInfo.InvariantCulture) },
                { "lng", options.Longitude.ToString(CultureInfo.InvariantCulture) }
            };

            // Optinal options
            if (options.Distance > 0)
            {
                qs.Add("distance", options.Distance + "");
            }
            if (options.MinTimestamp > 0)
            {
                qs.Add("min_timestamp", options.MinTimestamp + "");
            }
            if (options.MaxTimestamp > 0)
            {
                qs.Add("max_timestamp", options.MaxTimestamp + "");
            }

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/media/search", qs));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the most recent media published by a user.
        /// </summary>
        /// <param name="identifier">The identifier of the user.</param>
        /// <param name="options">The search options with any optional parameters.</param>
        /// <returns>Returns the raw JSON response from the API.</returns>
        public string GetRecentMedia(string identifier, InstagramMediaSearchOptions options)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken }
            };

            // Add any optional parameters
            if (options != null)
            {
                if (options.Count > 0)
                {
                    qs.Add("count", options.Count + "");
                }
                if (options.MinId != null)
                {
                    qs.Add("min_id", options.MinId + "");
                }
                if (options.MaxId != null)
                {
                    qs.Add("max_id", options.MaxId + "");
                }
            }

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/users/" + identifier + "/media/recent/", qs));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the feed of the specified user or page.
        /// </summary>
        /// <param name="identifier">The ID or name of the user/page.</param>
        /// <param name="options">The options for the call to the API.</param>
        /// <returns>The raw JSON response from the API.</returns>
        public string GetFeed(string identifier, FacebookFeedOptions options)
        {
            // Declare the query string
            NameValueCollection query = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(Client.AccessToken))
            {
                query.Add("access_token", Client.AccessToken);
            }
            if (options.Limit > 0)
            {
                query.Add("limit", options.Limit + "");
            }
            if (options.Since > 0)
            {
                query.Add("since", options.Since + "");
            }
            if (options.Until > 0)
            {
                query.Add("until", options.Until + "");
            }

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/" + identifier + "/feed", query));
        }
Ejemplo n.º 4
0
        public string ListVideos(YouTubeVideoOptions options)
        {
            // Initialize the query
            NameValueCollection query = new NameValueCollection {
                { "part", "id,snippet,contentDetails,fileDetails,liveStreamingDetails,player,processingDetails,recordingDetails,statistics,status,suggestions,topicDetails" },
                { "access_token", Client.AccessToken },
                { "key", Client.ApiKey }
            };

            // Optional parameters
            if (options != null)
            {
                if (options.Ids != null && options.Ids.Length > 0)
                {
                    query.Add("id", String.Join(",", options.Ids));
                }
                if (options.MaxResults > 0)
                {
                    query.Add("maxResults", options.MaxResults + "");
                }
                if (!String.IsNullOrWhiteSpace(options.PageToken))
                {
                    query.Add("pageToken", options.PageToken);
                }
            }

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/videos", query));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the raw JSON response from the Instagram API with media from the specified <code>tag</code>.
        /// </summary>
        /// <param name="tag">The name of the tag.</param>
        /// <param name="minTagId"></param>
        /// <param name="maxTagId"></param>
        public string GetRecentMedia(string tag, string minTagId = null, string maxTagId = null)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(Client.AccessToken))
            {
                qs.Add("access_token", Client.AccessToken);
            }
            else if (!String.IsNullOrWhiteSpace(Client.ClientId))
            {
                qs.Add("client_id", Client.ClientId);
            }

            // Add any optional parameters
            if (!String.IsNullOrWhiteSpace(minTagId))
            {
                qs.Add("min_tag_id", minTagId);
            }
            if (!String.IsNullOrWhiteSpace(maxTagId))
            {
                qs.Add("max_tag_id", maxTagId);
            }

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/tags/" + tag + "/media/recent/", qs));
        }
Ejemplo n.º 6
0
 public string GetPlaylistsFromChannel(string channelId, YouTubePlaylistPartsCollection parts)
 {
     return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/playlists", new NameValueCollection {
         { "part", parts.ToString() },
         { "channelId", channelId },
         { "access_token", Client.AccessToken }
     }));
 }
Ejemplo n.º 7
0
 public string GetPlaylistsFromIds(string[] playlistIds, YouTubePlaylistPartsCollection parts)
 {
     return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/playlists", new NameValueCollection {
         { "part", parts.ToString() },
         { "id", String.Join(",", playlistIds) },
         { "access_token", Client.AccessToken }
     }));
 }
Ejemplo n.º 8
0
 public string GetMyPlaylists(YouTubePlaylistPartsCollection parts)
 {
     return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/playlists", new NameValueCollection {
         { "part", parts.ToString() },
         { "mine", "true" },
         { "access_token", Client.AccessToken }
     }));
 }
        public string GetUserInfo()
        {
            // Declare the query string
            NameValueCollection query = new NameValueCollection {
                { "access_token", AccessToken },
            };

            // Make a call to the server
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/oauth2/v3/userinfo", query));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a status message with the specified ID.
        /// </summary>
        /// <param name="statusMessageId">The ID of the status message.</param>
        public string GetStatusMessage(string statusMessageId)
        {
            // Construct the query string
            NameValueCollection query = new NameValueCollection {
                { "access_token", Client.AccessToken }
            };

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/" + statusMessageId, query));
        }
Ejemplo n.º 11
0
        public string GetChannelVideosAsRawJson(string id, int page)
        {
            NameValueCollection query = new NameValueCollection();

            if (page > 0)
            {
                query.Set("page", page + "");
            }
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("http://vimeo.com/api/v2/channel/" + id + "/videos.json", query));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets information about a media object.
        /// </summary>
        /// <param name="mediaId">The ID of the media.</param>
        public string GetMedia(string mediaId)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken }
            };

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/media/" + mediaId, qs));
        }
Ejemplo n.º 13
0
        public string GetMyChannels(YouTubeChannelPartsCollection parts)
        {
            NameValueCollection query = new NameValueCollection();

            query.Add("part", parts.ToString());
            query.Add("mine", "true");
            query.Add("access_token", Client.AccessToken);

            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/channels", query));
        }
Ejemplo n.º 14
0
        public string GetVideoDetails(string id)
        {
            NameValueCollection query = new NameValueCollection();

            query.Add("id", id);
            query.Add("part", "snippet,contentDetails,fileDetails,player,processingDetails,recordingDetails,statistics,status,suggestions,topicDetails");
            query.Add("access_token", Client.AccessToken);

            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/videos", query));
        }
Ejemplo n.º 15
0
        public string GetChannelForUsername(YouTubeChannelPartsCollection parts, string userName)
        {
            NameValueCollection query = new NameValueCollection();

            query.Add("part", parts.ToString());
            query.Add("forUsername", userName);
            query.Add("access_token", Client.AccessToken);
            query.Add("key", Client.ApiKey);

            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/youtube/v3/channels", query));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets debug information about the specified access token.
        /// </summary>
        /// <param name="accessToken">The access token to debug.</param>
        /// <returns>The raw JSON response from the API.</returns>
        public string DebugToken(string accessToken)
        {
            // Declare the query string
            NameValueCollection query = new NameValueCollection {
                { "input_token", accessToken },
                { "access_token", Client.AccessToken }
            };

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/debug_token", query));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets the feed of the specified URL. This method can be used for paging purposes.
 /// </summary>
 /// <param name="url">The raw URL to call.</param>
 /// <returns>The raw JSON response from the API.</returns>
 public string GetFeedFromUrl(string url)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     if (!url.StartsWith("https://graph.facebook.com/"))
     {
         throw new ArgumentException("Invalid URL", "url");
     }
     return(SocialUtils.DoHttpGetRequestAndGetBodyAsString(url));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets information about the specified app.
        /// </summary>
        /// <param name="identifier">The identifier of the app. Can either be "app" or the ID of the app.</param>
        /// <returns>The raw JSON response from the API.</returns>
        public string GetApp(string identifier = "app")
        {
            // Declare the query string
            NameValueCollection query = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(Client.AccessToken))
            {
                query.Add("access_token", Client.AccessToken);
            }

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/" + identifier, query));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Search for a location by geographic coordinate.
        /// </summary>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <param name="distance">The distance is menters (max: 5000m)</param>
        public string Search(double latitude, double longitude, int distance)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken },
                { "lat", latitude.ToString(CultureInfo.InvariantCulture) },
                { "lng", longitude.ToString(CultureInfo.InvariantCulture) },
                { "distance", distance + "" }
            };

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/locations/search", qs));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the realtime data from the specified profile and options.
        /// </summary>
        /// <param name="profileId">The ID of the Analytics profile.</param>
        /// <param name="options">The options specifying the query.</param>
        public string GetRealtimeData(string profileId, AnalyticsRealtimeDataOptions options)
        {
            // Validate arguments
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Generate the name value collection
            NameValueCollection query = options.ToNameValueCollection(profileId, Client.AccessToken);

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/analytics/v3/data/realtime", query));
        }
        /// <summary>
        /// Makes an authenticated GET request to the specified URL. The access token is
        /// automatically appended to the query string.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="query">The query string for the call.</param>
        public string DoAuthenticatedGetRequest(string url, NameValueCollection query)
        {
            // Initialize a new NameValueCollection if NULL
            if (query == null)
            {
                query = new NameValueCollection();
            }

            // Set the access token in the query string
            // TODO: Specify access token in HTTP header instead
            query.Set("access_token", AccessToken);

            // Make a call to the server
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString(url, query));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get a list of recent media objects from a given location.
        /// </summary>
        /// <param name="locationId">The ID of the location.</param>
        public string GetRecentMedia(int locationId)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken }
            };

            // TODO: Add support for MIN_TIMESTAMP parameter
            // TODO: Add support for MIN_ID parameter
            // TODO: Add support for MAX_ID parameter
            // TODO: Add support for MAX_TIMESTAMP parameter

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/locations/" + locationId + "/media/recent", qs));
        }
Ejemplo n.º 23
0
        public string GetWebProperties(string accountId, int maxResults = 0, int startIndex = 0)
        {
            NameValueCollection query = new NameValueCollection();

            if (maxResults > 0)
            {
                query.Add("max-results", maxResults + "");
            }
            if (startIndex > 0)
            {
                query.Add("start-index", startIndex + "");
            }
            query.Add("access_token", Client.AccessToken);

            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/analytics/v3/management/accounts/" + accountId + "/webproperties", query));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Gets the events of the specified user or page.
        /// </summary>
        /// <param name="identifier">The ID or name of the user/page.</param>
        /// <param name="limit">The maximum amount of events to return.</param>
        /// <returns>The raw JSON response from the API.</returns>
        public string GetEvents(string identifier, int limit = 0)
        {
            // Declare the query string
            NameValueCollection query = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(Client.AccessToken))
            {
                query.Add("access_token", Client.AccessToken);
            }
            if (limit > 0)
            {
                query.Add("limit", limit + "");
            }

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/" + identifier + "/events", query));
        }
Ejemplo n.º 25
0
        // TODO: Implement /users/self/media/liked

        /// <summary>
        /// Search for a user by name.
        /// </summary>
        /// <param name="query">A query string.</param>
        /// <param name="count">Number of users to return.</param>
        public string Search(string query, int count = 0)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection {
                { "access_token", Client.AccessToken },
                { "q", query }
            };

            // Optional
            if (count > 0)
            {
                qs.Add("count", count + "");
            }

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/users/search", qs));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets the raw JSON response from the Instagram API with information about the specified <code>tag</code>.
        /// </summary>
        /// <param name="tag">The name of the tag.</param>
        public string GetTagInfo(string tag)
        {
            // Declare the query string
            NameValueCollection qs = new NameValueCollection();

            if (!String.IsNullOrWhiteSpace(Client.AccessToken))
            {
                qs.Add("access_token", Client.AccessToken);
            }
            else if (!String.IsNullOrWhiteSpace(Client.ClientId))
            {
                qs.Add("client_id", Client.ClientId);
            }

            // Perform the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://api.instagram.com/v1/tags/" + tag, qs));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Gets an app access token for for the application. An app id and app secret must be present.
        /// </summary>
        public string GetAppAccessToken()
        {
            // Initialize the query string
            NameValueCollection query = new NameValueCollection {
                { "client_id", AppId },
                { "client_secret", AppSecret },
                { "grant_type", "client_credentials" }
            };

            // Make the call to the API
            string contents = SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/oauth/access_token", query);

            // Parse the contents
            NameValueCollection response = HttpUtility.ParseQueryString(contents);

            // Get the access token
            return(response["access_token"]);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Exchanges the specified authorization code for a user access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Facebook OAuth dialog.</param>
        public string GetAccessTokenFromAuthCode(string authCode)
        {
            // Initialize the query string
            NameValueCollection query = new NameValueCollection {
                { "client_id", AppId },
                { "redirect_uri", RedirectUri },
                { "client_secret", AppSecret },
                { "code", authCode }
            };

            // Make the call to the API
            string contents = SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://graph.facebook.com/oauth/access_token", query);

            // Parse the contents
            NameValueCollection response = HttpUtility.ParseQueryString(contents);

            // Get the access token
            return(response["access_token"]);
        }
        /// <summary>
        /// Makes an authenticated GET request to the specified URL. If an access token has been
        /// specified for this client, that access token will be added to the query string.
        /// Similar if a client ID has been specified instead of an access token, that client ID
        /// will be added to the query string. However some endpoint methods may require an access
        /// token, and a client ID will therefore not be sufficient for such methods.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="query">The query string for the call.</param>
        public string DoAuthenticatedGetRequest(string url, NameValueCollection query)
        {
            // Initialize a new NameValueCollection if NULL
            if (query == null)
            {
                query = new NameValueCollection();
            }

            // Set the access token ot client ID in the query string
            if (!String.IsNullOrWhiteSpace(AccessToken))
            {
                query.Add("access_token", AccessToken);
            }
            else if (!String.IsNullOrWhiteSpace(ClientId))
            {
                query.Add("client_id", ClientId);
            }

            // Make a call to the server
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString(url, query));
        }
        public static string GetData(this AnalyticsRawEndpoint endpoint, string profileId, DateTime startDate, DateTime endDate, string[] metrics, string[] dimensions, string[] filters, string[] sort)
        {
            // Initialize the query string
            NameValueCollection query = new NameValueCollection();

            query.Add("ids", "ga:" + profileId);
            query.Add("start-date", startDate.ToString("yyyy-MM-dd"));
            query.Add("end-date", endDate.ToString("yyyy-MM-dd"));
            query.Add("metrics", String.Join(",", metrics));
            query.Add("dimensions", String.Join(",", dimensions));
            if (filters != null && filters.Length > 0)
            {
                query.Add("filters", String.Join(",", filters));
            }
            if (sort != null && sort.Length > 0)
            {
                query.Add("sort", String.Join(",", sort));
            }
            query.Add("access_token", endpoint.Client.AccessToken);

            // Make the call to the API
            return(SocialUtils.DoHttpGetRequestAndGetBodyAsString("https://www.googleapis.com/analytics/v3/data/ga", query));
        }