コード例 #1
0
        public override async Task <ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
        {
            // ツイートに位置情報が付与されている場合は何もしない
            if (post.PostGeo != null)
            {
                return(null);
            }

            var location = await this.FetchCheckinLocation(url, token)
                           .ConfigureAwait(false);

            if (location == null)
            {
                location = await this.FetchCheckinLocationLegacy(url, token)
                           .ConfigureAwait(false);
            }

            if (location != null)
            {
                var map = MapThumb.GetDefaultInstance();

                return(await map.GetThumbnailInfoAsync(new PostClass.StatusGeo(location.Longitude, location.Latitude))
                       .ConfigureAwait(false));
            }

            return(null);
        }
コード例 #2
0
        public string GetMapsUri(string url, ref string refText)
        {
            if (!AppendSettingDialog.Instance.IsPreviewFoursquare)
            {
                return(null);
            }

            var urlId = Regex.Replace(url, @"https?://(4sq|foursquare)\.com/", "");

            if (CheckInUrlsVenueCollection.ContainsKey(urlId))
            {
                refText = CheckInUrlsVenueCollection[urlId].LocateInfo;
                return(MapThumb.GetDefaultInstance().CreateStaticMapUrl(CheckInUrlsVenueCollection[urlId]));
            }

            FourSquareDataModel.Venue curVenue = null;
            var venueId = GetVenueId(url);

            if (string.IsNullOrEmpty(venueId))
            {
                return(null);
            }

            curVenue = GetVenueInfo(venueId);
            if (curVenue == null)
            {
                return(null);
            }

            var curLocation = new GlobalLocation {
                Latitude = curVenue.Location.Latitude, Longitude = curVenue.Location.Longitude, LocateInfo = CreateVenueInfoText(curVenue)
            };

            //例外発生の場合があるため
            if (!CheckInUrlsVenueCollection.ContainsKey(urlId))
            {
                CheckInUrlsVenueCollection.Add(urlId, curLocation);
            }
            refText = curLocation.LocateInfo;
            return(MapThumb.GetDefaultInstance().CreateStaticMapUrl(curLocation));
        }
コード例 #3
0
        public override async Task <ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
        {
            // ツイートに位置情報が付与されている場合は何もしない
            if (post.PostGeo.Lat != 0 || post.PostGeo.Lng != 0)
            {
                return(null);
            }

            var match = UrlPatternRegex.Match(url);

            if (!match.Success)
            {
                return(null);
            }

            var checkinIdGroup = match.Groups["checkin_id"];
            var signatureGroup = match.Groups["signature"];

            try
            {
                // Foursquare のベニュー情報を取得
                // 参照: https://developer.foursquare.com/docs/venues/venues

                var query = new Dictionary <string, string>
                {
                    { "client_id", ApplicationSettings.FoursquareClientId },
                    { "client_secret", ApplicationSettings.FoursquareClientSecret },
                    { "v", "20140419" }, // https://developer.foursquare.com/overview/versioning
                };

                if (signatureGroup.Success)
                {
                    query["signature"] = signatureGroup.Value;
                }

                var apiUrl = new Uri(ApiBase + "/checkins/" + checkinIdGroup.Value + "?" + MyCommon.BuildQueryString(query));

                using (var response = await this.http.GetAsync(apiUrl, token).ConfigureAwait(false))
                {
                    response.EnsureSuccessStatusCode();

                    var jsonBytes = await response.Content.ReadAsByteArrayAsync()
                                    .ConfigureAwait(false);

                    var location = ParseIntoLocation(jsonBytes);
                    if (location == null)
                    {
                        return(null);
                    }

                    var map = MapThumb.GetDefaultInstance();

                    return(new ThumbnailInfo
                    {
                        ImageUrl = map.CreateMapLinkUrl(location.Latitude, location.Longitude),
                        ThumbnailUrl = map.CreateStaticMapUrl(location.Latitude, location.Longitude),
                        TooltipText = null,
                    });
                }
            }
            catch (HttpRequestException) { }

            return(null);
        }