Пример #1
0
 public FacebookWebApi(FacebookService service, string secret)
 {
     _ApplicationKey = service.ApplicationKey;
     _SessionKey     = service.SessionKey;
     _UserId         = service.UserId;
     _Secret         = secret;
     _Service        = service;
     _jsonSerializer = new JsonDataSerialization(service);
 }
Пример #2
0
 public FacebookWebApi(string applicationId, string sessionKey, FacebookObjectId userId, string secret)
 {
     _ApplicationKey = applicationId;
     _SessionKey     = sessionKey;
     _UserId         = userId;
     _Secret         = secret;
     _Service        = null;
     _jsonSerializer = new JsonDataSerialization(null);
 }
Пример #3
0
        private static DateTime?_SafeGetDateTime(JSON_OBJECT jsonObj, params string[] names)
        {
            long?ticks = _SafeGetInt64(jsonObj, names);

            if (ticks == null)
            {
                return(null);
            }

            return(JsonDataSerialization.GetDateTimeFromUnixTimestamp(ticks.Value));
        }
Пример #4
0
        /// <summary>Check the response of a Facebook server call for error information.</summary>
        /// <param name="xml"></param>
        /// <returns>
        /// If the request was an error, returns an exception that describes the failure.
        /// Otherwise this returns null.
        private static Exception _VerifyJsonResult(string jsonInput, string sourceRequest)
        {
            try
            {
                return(JsonDataSerialization.DeserializeFacebookException(jsonInput, sourceRequest));
            }
            catch (InvalidOperationException) { }

            // Yay, couldn't convert to an exception :) return null.
            return(null);
        }
Пример #5
0
        public List <FacebookPhoto>[] GetPhotosWithTags(IEnumerable <FacebookObjectId> albumIds)
        {
            var names   = new List <string>();
            var queries = new List <string>();

            int albumCount = 0;

            foreach (FacebookObjectId albumId in albumIds)
            {
                names.Add("get_photos" + albumCount);
                names.Add("get_tags" + albumCount);

                queries.Add(string.Format(_GetPhotosFromAlbumQueryString, albumId.ToString()));
                queries.Add(string.Format(_GetPhotoTagsMultiQueryString, "get_photos" + albumCount));
                ++albumCount;
            }

            string photoMultiQueryResult = Utility.FailableFunction(() => _SendMultiQuery(names, queries));

            JSON_ARRAY jsonMultiqueryArray = JsonDataSerialization.SafeParseArray(photoMultiQueryResult);

            var photoCollections = new List <FacebookPhoto> [albumCount];

            albumCount = 0;
            foreach (FacebookObjectId albumId in albumIds)
            {
                JSON_ARRAY photosResponseArray = (from JSON_OBJECT result in jsonMultiqueryArray
                                                  where result.Get <string>("name") == "get_photos" + albumCount
                                                  select result.Get <JSON_ARRAY>("fql_result_set"))
                                                 .First();
                List <FacebookPhoto> photos = _jsonSerializer.DeserializePhotosGetResponse(photosResponseArray);

                JSON_ARRAY tagsResponseArray = (from JSON_OBJECT result in jsonMultiqueryArray
                                                where result.Get <string>("name") == "get_tags" + albumCount
                                                select result.Get <JSON_ARRAY>("fql_result_set"))
                                               .First();
                List <FacebookPhotoTag> tags = _jsonSerializer.DeserializePhotoTagsList(tagsResponseArray);

                foreach (var photo in photos)
                {
                    photo.RawTags.Merge(from tag in tags where tag.PhotoId == photo.PhotoId select tag, false);
                }

                photoCollections[albumCount] = photos;
                ++albumCount;
            }
            return(photoCollections);
        }
Пример #6
0
        public List <ActivityPost> GetStream(FacebookObjectId filterKey, int limit, DateTime getItemsSince)
        {
            Assert.IsTrue(limit > 0);

            // Facebook changed the semantics of the default feed, so we need to explicitly
            // request the newsfeed filter to keep things working as expected.
            // I think everyone should have a filter with this key, but this is unfortunately fragile.
            if (!FacebookObjectId.IsValid(filterKey))
            {
                filterKey = new FacebookObjectId("nf");
            }

            long startTime = JsonDataSerialization.GetUnixTimestampFromDateTime(getItemsSince);

            Assert.IsTrue(startTime >= 0);

            // Don't use metadata field.  Facebook regressed support for it.
            // Getting profile data needs to be simulated at a higher level.
            var streamMap = new METHOD_MAP
            {
                { "method", "stream.get" },
                { "viewer_id", _UserId.ToString() },
                { "start_time", startTime.ToString("G") },
                { "limit", limit.ToString("G") },
                { "filter_key", filterKey.ToString() },
            };

            string result = Utility.FailableFunction(() => _SendRequest(streamMap));

            return(_jsonSerializer.DeserializeStreamData(result));

            //var userIds = new HashSet<FacebookObjectId>();
            //foreach (var post in posts)
            //{
            //    userIds.Add(post.ActorUserId);
            //    userIds.Add(post.TargetUserId);
            //    userIds.AddRange(from comment in post.Comments select comment.FromUserId);
            //    userIds.AddRange(from liker in post.PeopleWhoLikeThis select liker.UserId);
            //}
        }