/// <summary>
        /// Returns the <see cref="FacebookPicture"/> object associated with the logged user
        /// </summary>
        /// <returns>A <see cref="FacebookPicture"/> object</returns>
        public async Task <FacebookPicture> GetUserPictureInfoAsync()
        {
            if (Provider.LoggedIn)
            {
                var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookDataHost <FacebookPicture> >);

                PropertySet propertySet = new PropertySet {
                    { "redirect", "0" }
                };
                var singleValue = new FBSingleValue("/me/picture", propertySet, factory);

                var result = await singleValue.GetAsync();

                if (result.Succeeded)
                {
                    return(((FacebookDataHost <FacebookPicture>)result.Object).Data);
                }

                throw new Exception(result.ErrorInfo?.Message);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await GetUserPictureInfoAsync());
            }

            return(null);
        }
Esempio n. 2
0
        private async Task <string> getAppToken()
        {
            PropertySet parameters = new PropertySet();
            string      result     = null;

            parameters.Add("request_host", FBSDKTokenServiceHost);
            parameters.Add("access_token", "");
            parameters.Add("id", TestAppId);

            FBSingleValue sval = new FBSingleValue(FBSDKTokenApiPath,
                                                   parameters,
                                                   new FBJsonClassFactory((JsonText) =>
            {
                JsonObject obj = null;
                if (!JsonObject.TryParse(JsonText, out obj))
                {
                    obj = null;
                }

                return(obj);
            }));

            FBResult fbresult = await sval.Get();

            if (fbresult.Succeeded)
            {
                JsonObject obj = (JsonObject)fbresult.Object;
                if (obj.Keys.Contains("access_token"))
                {
                    result = obj.GetNamedString("access_token");
                }
            }

            return(result);
        }
        /// <summary>
        /// Retrieves a photo by id.
        /// </summary>
        /// <param name="photoId">Photo Id for the photo.</param>
        /// <returns>A single photo.</returns>
        public async Task <FacebookPhoto> GetPhotoByPhotoIdAsync(string photoId)
        {
            if (Provider.LoggedIn)
            {
                var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPhoto>);

                PropertySet propertySet = new PropertySet {
                    { "fields", "images" }
                };
                var singleValue = new FBSingleValue($"/{photoId}", propertySet, factory);

                var result = await singleValue.GetAsync();

                if (result.Succeeded)
                {
                    return((FacebookPhoto)result.Object);
                }

                throw new Exception(result.ErrorInfo?.Message);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await GetPhotoByPhotoIdAsync(photoId));
            }

            return(null);
        }
Esempio n. 4
0
        public async void makeGraphRequest(
            string path,
            JObject parameters,
            string version,
            string method,
            IPromise promise)
        {
            if (version != null)
            {
                throw new NotSupportedException("Version parameter is not currently supported.");
            }

            var propertySet = new PropertySet();

            foreach (var pair in parameters)
            {
                propertySet.Add(pair.Key, pair.Value);
            }

            var request = new FBSingleValue(path, propertySet, s_jsonFactory);
            var result  = await ExecuteAsync(method, request);

            if (result.Succeeded)
            {
                promise.Resolve(result.Object);
            }
            else
            {
                promise.Reject(result.ErrorInfo.Message);
            }
        }
Esempio n. 5
0
        private async void getFBUserInfo()
        {
            FBSession clicnt = FBSession.ActiveSession;

            if (clicnt.LoggedIn)
            {
                var    userId   = clicnt.User.Id;
                string endpoint = "/" + userId + "?access_token=1819087251640431|n5eZecurPAfO37og6RphwZ04tb8&fields=id,name,email,picture";

                PropertySet   parameters  = new PropertySet();
                FBSingleValue value       = new FBSingleValue(endpoint, parameters, FBUserRootobject.FromJson);
                FBResult      graphResult = await value.GetAsync();

                if (graphResult.Succeeded)
                {
                    try
                    {
                        FBUserRootobject profile = graphResult.Object as FBUserRootobject;
                        FBPicture.UserId = userId;
                        getFBUserDetails(profile);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString() + "\nBrak danych");
                    }
                }
            }
        }
Esempio n. 6
0
        private async void OnGet(object sender, RoutedEventArgs e)
        {
            FBSession clicnt = FBSession.ActiveSession;

            if (clicnt.LoggedIn)
            {
                var    userId   = clicnt.User.Id;
                string endpoint = "/" + userId + "/friends?fields=id,name,email,picture";

                PropertySet parameters = new PropertySet();
                // parameters.Add("limit", "10");

                FBSingleValue value       = new FBSingleValue(endpoint, parameters, Rootobject.FromJson);
                FBResult      graphResult = await value.GetAsync();

                if (graphResult.Succeeded)
                {
                    try
                    {
                        Rootobject    profile = graphResult.Object as Rootobject;
                        string        name    = profile.data[0]?.name;
                        string        email   = profile.data[0]?.email;
                        MessageDialog dialog  = new MessageDialog(name + "\n" + email);
                        await dialog.ShowAsync();
                    }
                    catch (Exception ex)
                    {
                        MessageDialog dialog = new MessageDialog(ex.ToString() + "\nBrak znajomych");
                        await dialog.ShowAsync();
                    }
                }
            }
        }
Esempio n. 7
0
        private async void GetFriends()
        {
            FBSession clicnt = FBSession.ActiveSession;

            if (clicnt.LoggedIn)
            {
                var         userId     = clicnt.User.Id;
                string      endpoint   = "/" + userId + "/friends?fields=id,name,email,picture";
                PropertySet parameters = new PropertySet();
                //parameters.Add("limit", "3");
                FBSingleValue value       = new FBSingleValue(endpoint, parameters, Rootobject.FromJson);
                FBResult      graphResult = await value.GetAsync();

                if (graphResult.Succeeded)
                {
                    try
                    {
                        Rootobject profile       = graphResult.Object as Rootobject;
                        int        friends_count = profile.data.Count();
                        if (Convert.ToBoolean(friends_count))
                        {
                            var friendsList = new ObservableCollection <FBUserRootobject>();
                            for (int i = 0; i < friends_count; i++)
                            {
                                string id = profile.data[i]?.id;
                                if (Database.checkIfFBUserIsSigned(id, course_id))
                                {
                                    friendsList.Add(new FBUserRootobject()
                                    {
                                        id = profile.data[i]?.id, name = profile.data[i]?.name, email = profile.data[i]?.email
                                    });
                                    Debug.WriteLine("Friend {0} added to friends list.", i + 1);
                                }
                            }
                            if (friendsList.Count > 0)
                            {
                                TitleFbFriendsTextBlock.Visibility = Visibility.Visible;
                                FriendsList.ItemsSource            = friendsList;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageDialog dialog = new MessageDialog(ex.ToString());
                        await dialog.ShowAsync();
                    }
                }
            }
        }
Esempio n. 8
0
        public async Task testUploadPhoto()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions", FBTestPhotoUploadPermissions);

            FBTestUser user = await createTestUser(parameters);

            StorageFolder appFolder =
                Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile f = await appFolder.GetFileAsync(
                FBTestImagePath);

            IRandomAccessStreamWithContentType stream = await f.OpenReadAsync();

            Assert.IsNotNull(stream);

            FBMediaStream fbStream = new FBMediaStream(FBTestImageName,
                                                       stream);

            // Switch to user access token to post photo.
            parameters.Remove("access_token");
            parameters.Add("access_token", user.AccessToken);

            parameters.Add("source", fbStream);

            string path = "/" + user.Id + "/photos";

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBPhoto.FromJson));

            FBResult result = await sval.Post();

            Assert.IsTrue(result.Succeeded);

            try
            {
                FBPhoto pic = (FBPhoto)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                               "expected type (FBPhoto).");
            }
        }
Esempio n. 9
0
        public async Task <FBResult> deleteTestUser(
            FBTestUser user
            )
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();
            string      path       = "/" + user.Id;

            parameters.Add("access_token", Uri.EscapeUriString(token));

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBSuccess.FromJson));

            return(await sval.Delete());
        }
Esempio n. 10
0
        public async Task <FBResult> publishCustomUserObject(
            FBTestUser user
            )
        {
            PropertySet parameters = new PropertySet();
            string      path       = user.Id + "/objects/logincs:noun";

            Assert.IsNotNull(user.AccessToken);
            parameters.Add("access_token", user.AccessToken);
            parameters.Add("object", FBCustomObjectInstance);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            return(await sval.Post());
        }
Esempio n. 11
0
        public async Task <FBResult> publishCustomStory(
            FBTestUser user,
            FBObject customObject
            )
        {
            PropertySet parameters = new PropertySet();
            string      path       = user.Id + "/logincs:verb";

            parameters.Add("noun", customObject.Id);
            parameters.Add("access_token", user.AccessToken);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            return(await sval.Post());
        }
Esempio n. 12
0
        private async void OnGet(object sender, RoutedEventArgs e)
        {
            string      endpoint   = "/me";
            PropertySet parameters = new PropertySet();

            parameters.Add("fields", "email");
            FBSingleValue value       = new FBSingleValue(endpoint, parameters, User.FromJson);
            FBResult      graphResult = await value.GetAsync();

            if (graphResult.Succeeded)
            {
                User          profile = graphResult.Object as User;
                string        email   = profile?.Email;
                MessageDialog dialog  = new MessageDialog(email);
                await dialog.ShowAsync();
            }
        }
Esempio n. 13
0
        private async Task <FBTestUser> createTestUser(
            PropertySet Parameters
            )
        {
            FBTestUser user    = null;
            bool       success = false;

            // If you're creating/deleting test users frequently, like say in
            // a unit test suite, Facebook will occasionally fail this call with
            // the error code 1, type "OAuthException" and the message "An
            // unknown error occurred".  Throwing in a short delay and retrying
            // almost always alleviates the problem, so adding a few retries
            // here greatly increases the robustness of the test suite.
            for (int retries = 0; (success == false) && (retries < 5);
                 retries++)
            {
                string path = "/" + TestAppId + FBSDKTestUsersPath;

                FBSingleValue sval = new FBSingleValue(path, Parameters,
                                                       new FBJsonClassFactory(FBTestUser.FromJson));

                FBResult fbresult = await sval.Post();

                if ((fbresult.Succeeded == false) || (fbresult.Object == null))
                {
                    await Task.Delay(TEST_RETRY_DELAY);
                }
                else
                {
                    try
                    {
                        user    = (FBTestUser)fbresult.Object;
                        success = true;
                    }
                    catch (InvalidCastException)
                    {
                        Assert.IsTrue(false, "Item returned is not expected type" +
                                      " (FBTestUser)");
                    }
                }
            }

            Assert.IsNotNull(user);

            return(user);
        }
Esempio n. 14
0
        private static IAsyncOperation <FBResult> ExecuteAsync(string method, FBSingleValue request)
        {
            switch (method.ToLowerInvariant())
            {
            case "delete":
                return(request.DeleteAsync());

            case "get":
                return(request.GetAsync());

            case "post":
                return(request.PostAsync());

            default:
                throw new NotSupportedException($"Method '{method}' is not supported.");
            }
        }
Esempio n. 15
0
 public async void GetPageWithId(
     string ID
     )
 {
     FBSingleValue val = new FBSingleValue("/" + ID, null,
         new FBJsonClassFactory((JsonText) => 
             MyFBPage.FromJson(JsonText)));
     FBResult result = await val.GetAsync();
     if (result.Succeeded)
     {
         MyFBPage page = (MyFBPage)result.Object;
         //Do something with page here
     }
     else
     {
         HandleError(result.ErrorInfo);
     }
 }
Esempio n. 16
0
        private async Task <FBObject> postToFeed(
            FBTestUser User,
            string Message
            )
        {
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", User.AccessToken);
            parameters.Add("message", Message);

            string path = "/" + User.Id + FBFeedPath;

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            FBResult fbresult = await sval.Post();

            return((FBObject)fbresult.Object);
        }
        public async Task <string> PostPictureToFeedAsync(string title, string pictureName, IRandomAccessStreamWithContentType pictureStream)
        {
            if (pictureStream == null)
            {
                return(null);
            }

            if (Provider.LoggedIn)
            {
                var facebookPictureStream = new FBMediaStream(pictureName, pictureStream);
                var parameters            = new PropertySet
                {
                    { "source", facebookPictureStream },
                    { "name", title }
                };

                string path    = FBSession.ActiveSession.User.Id + "/photos";
                var    factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPicture>);

                var singleValue = new FBSingleValue(path, parameters, factory);
                var result      = await singleValue.PostAsync();

                if (result.Succeeded)
                {
                    var photoResponse = result.Object as FacebookPicture;
                    if (photoResponse != null)
                    {
                        return(photoResponse.Id);
                    }
                }

                return(null);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await PostPictureToFeedAsync(title, pictureName, pictureStream));
            }

            return(null);
        }
Esempio n. 18
0
        private async void OnGet(object sender, RoutedEventArgs e)
        {
            string endpoint = "/me/friends";

            PropertySet parameters = new PropertySet();

            parameters.Add("limit", "10");

            FBSingleValue value       = new FBSingleValue(endpoint, parameters, Rootobject.FromJson);
            FBResult      graphResult = await value.GetAsync();

            if (graphResult.Succeeded)
            {
                Rootobject    profile = graphResult.Object as Rootobject;
                string        name    = profile.data[0]?.name;
                MessageDialog dialog  = new MessageDialog(name);
                await dialog.ShowAsync();
            }
        }
Esempio n. 19
0
        public async void GetPageWithId(
            string ID
            )
        {
            FBSingleValue val = new FBSingleValue("/" + ID, null,
                                                  new FBJsonClassFactory((JsonText) =>
                                                                         MyFBPage.FromJson(JsonText)));
            FBResult result = await val.GetAsync();

            if (result.Succeeded)
            {
                MyFBPage page = (MyFBPage)result.Object;
                //Do something with page here
            }
            else
            {
                HandleError(result.ErrorInfo);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Enables direct posting data to the timeline.
        /// </summary>
        /// <param name="title">Title of the post.</param>
        /// <param name="message">Message of the post.</param>
        /// <param name="description">Description of the post.</param>
        /// <param name="link">Link contained as part of the post. Cannot be null</param>
        /// <param name="pictureUrl">URL of a picture attached to this post. Can be null</param>
        /// <returns>Task to support await of async call.</returns>
        public async Task <bool> PostToFeedAsync(string title, string message, string description, string link, string pictureUrl = null)
        {
            if (Provider.LoggedIn)
            {
                var parameters = new PropertySet {
                    { "title", title }, { "message", link }, { "description", description }, { "link", link }
                };

                if (!string.IsNullOrEmpty(pictureUrl))
                {
                    parameters.Add(new KeyValuePair <string, object>("picture", pictureUrl));
                }

                string path    = FBSession.ActiveSession.User.Id + "/feed";
                var    factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPost>);

                var singleValue = new FBSingleValue(path, parameters, factory);
                var result      = await singleValue.PostAsync();

                if (result.Succeeded)
                {
                    var postResponse = result.Object as FacebookPost;
                    if (postResponse != null)
                    {
                        return(true);
                    }
                }

                Debug.WriteLine(string.Format("Could not post. {0}", result.ErrorInfo?.ErrorUserMessage));
                return(false);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await PostToFeedAsync(title, message, description, link, pictureUrl));
            }

            return(false);
        }
Esempio n. 21
0
        /*Method keeps sending get requets to facebook api using paging, untill all pictures have been added
         */
        private async void GetAllFbPic(PicturePlaceObject results, PropertySet parameters, string endpoint, PicturePlaceDb db)
        {
            Boolean addedAllPics = false;

            do                                            //only do this while there is a next page and all pics have not been added
            {
                addedAllPics = SortPictures(results, db); //Add Results to a list

                if (addedAllPics == false)
                {
                    parameters.Remove("after");                                                                    //Remove previous parameters
                    parameters.Add("after", results.paging.cursors.after);                                         //the next page to send the request too

                    FBSingleValue value       = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce
                    FBResult      graphResult = await value.GetAsync();                                            //check to see if the Requets Succeeded

                    results = graphResult.Object as PicturePlaceObject;
                }
            } while ((results.paging != null || results.data.Count() != 0) && addedAllPics == false);
            PaintPins(db);
        }
Esempio n. 22
0
        public async Task testLikeSomething()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions",
                           "public_profile,publish_actions,user_photos");

            FBTestUser user = await createTestUser(parameters);

            string path = user.Id + "/og.likes";

            // Because *everybody* likes these, amirite?
            string likedObject =
                Uri.EscapeUriString("http://en.wikipedia.org/wiki/Brussels_sprout");

            parameters.Add("object", likedObject);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                                                   new FBJsonClassFactory(FBObject.FromJson));

            FBResult result = await sval.Post();

            Assert.IsTrue(result.Succeeded);

            try
            {
                FBObject like = (FBObject)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                               "expected type (FBObject).");
            }
        }
        public async Task <bool> PostToFeedAsync(string link)
        {
            if (Provider.LoggedIn)
            {
                var parameters = new PropertySet {
                    { "link", link }
                };

                string path    = FBSession.ActiveSession.User.Id + "/feed";
                var    factory = new FBJsonClassFactory(JsonConvert.DeserializeObject <FacebookPost>);

                var singleValue = new FBSingleValue(path, parameters, factory);
                var result      = await singleValue.PostAsync();

                if (result.Succeeded)
                {
                    var postResponse = result.Object as FacebookPost;
                    if (postResponse != null)
                    {
                        return(true);
                    }
                }

                Debug.WriteLine(string.Format("Could not post. {0}", result.ErrorInfo?.ErrorUserMessage));
                return(false);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await PostToFeedAsync(link));
            }

            return(false);
        }
Esempio n. 24
0
        private async void LoadRoundProfilePicture(
            String UserId
            )
        {
            PropertySet parameters = new PropertySet();
            String      path       = "/" + UserId + "/picture";

            parameters.Add(new KeyValuePair <String, Object>("redirect", "false"));

            // Just picking a width and height for now
            parameters.Add(new KeyValuePair <String, Object>("width", "200"));
            parameters.Add(new KeyValuePair <String, Object>("height", "200"));

            FBSingleValue value = new FBSingleValue(path, parameters,
                                                    new FBJsonClassFactory(FBProfilePicture.FromJson));

            FBResult result = await value.GetAsync();

            if (result.Succeeded)
            {
                FBProfilePicture pic = (FBProfilePicture)result.Object;
                ProfilePicBrush.ImageSource = new BitmapImage(new Uri(pic.Url));
            }
        }
Esempio n. 25
0
        /*On Successful login, send GET request to FB endpoint with params and DeserializeJson the results into objects/Dictonary
         */
        private async void OnSuccessLogin()
        {
            string endpoint = "/me/photos";//where the url starts from

            PropertySet parameters = new PropertySet();

            parameters.Add("fields", "source,place");                                                      //Required fields needed

            FBSingleValue value       = new FBSingleValue(endpoint, parameters, DeserializeJson.FromJson); //send the request and get back a JSON responce
            FBResult      graphResult = await value.GetAsync();

            if (graphResult.Succeeded)//check to see if the Request Succeeded
            {
                PicturePlaceObject results = graphResult.Object as PicturePlaceObject;

                var db = new PicturePlaceDb();
                GetAllFbPic(results, parameters, endpoint, db);
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Try Again Later!");
                await dialog.ShowAsync();
            }
        }
Esempio n. 26
0
        private async Task<FBTestUser> createTestUser(
            PropertySet Parameters 
            )
        {
            FBTestUser user = null;
            bool success = false;

            // If you're creating/deleting test users frequently, like say in
            // a unit test suite, Facebook will occasionally fail this call with 
            // the error code 1, type "OAuthException" and the message "An 
            // unknown error occurred".  Throwing in a short delay and retrying
            // almost always alleviates the problem, so adding a few retries
            // here greatly increases the robustness of the test suite.
            for (int retries = 0; (success == false) && (retries < 5); 
                retries++)
            {
                string path = "/" + TestAppId + FBSDKTestUsersPath;

                FBSingleValue sval = new FBSingleValue(path, Parameters,
                    new FBJsonClassFactory(FBTestUser.FromJson));

                FBResult fbresult = await sval.PostAsync();
    
                if ((fbresult.Succeeded == false) || (fbresult.Object == null))
                {
                    await Task.Delay(TEST_RETRY_DELAY);
                }
                else
                {
                    try
                    {
                        user = (FBTestUser)fbresult.Object;
                        success = true;
                    }
                    catch (InvalidCastException)
                    {
                        Assert.IsTrue(false, "Item returned is not expected type" +
                            " (FBTestUser)");
                    }
                }
            }

            Assert.IsNotNull(user);

            return user;
        }
Esempio n. 27
0
        private async Task FacebookPoster()
        {
            // Get active session
            FBSession sess = FBSession.ActiveSession;

            SosPageText += "\n Getting active Facebook Session...";
            RaisePropertyChanged(() => SosPageText);

            if (sess.LoggedIn)
            {
                var user = sess.User;
                // Set caption, link and description parameters
                var parameters = new PropertySet();

                // Add post message
                await LocationAccesser();
                parameters.Add("message", Message + "\n" + "\n" + _latitude + "\n" + _longitude);

                // Set Graph api path
                var path = "/" + user.Id + "/feed";

                var factory = new FBJsonClassFactory(JsonConvert.DeserializeObject<FBReturnObject>);

                var singleValue = new FBSingleValue(path, parameters, factory);
                var result = await singleValue.PostAsync();
                if (result.Succeeded)
                {
                    SosPageText += "\n Posted to Facebook Wall \n";
                }
                else
                {
                    SosPageText += "\n Can't post to Facebook Wall \n";
                }
            }
            else
            {
                SosPageText += "\n Facebook Not Configured or Active session not available! ";
                RaisePropertyChanged(() => SosPageText);
            }
            RaisePropertyChanged(()=>SosPageText);
        }
Esempio n. 28
0
 private async void OnGetInfoClicked(object sender, RoutedEventArgs e)
 {
     string endpoint = "/me";
     FBSingleValue value = new FBSingleValue(endpoint, null, Entities.Profile.FromJson);
     FBResult result = await value.Get();
     if (result.Succeeded)
     {
         Profile profile = result.Object as Profile;
         string name = profile?.Name;
         MessageDialog dialog = new MessageDialog(name);
         await dialog.ShowAsync();
     }
 }
Esempio n. 29
0
        private static async void FacebookPoster()
        {
            // Get active session
            FBSession sess = FBSession.ActiveSession;


            if (sess.LoggedIn)
            {
                var user = sess.User;
                // Set caption, link and description parameters
                var parameters = new PropertySet();

                // Add post message
                await LocationAccesser();
                parameters.Add("message", _message + "\n" + "\n" + _latitude + "\n" + _longitude);

                // Set Graph api path
                var path = "/" + user.Id + "/feed";

                var factory = new FBJsonClassFactory(s => {
                    return JsonConvert.DeserializeObject<FBReturnObject>(s);
                });

                var singleValue = new FBSingleValue(path, parameters, factory);
                var result = await singleValue.PostAsync();
                if (result.Succeeded)
                {
                    Debug.WriteLine("Succeed");
                }
                else
                {
                    Debug.WriteLine("Failed");
                }
            }
        }
Esempio n. 30
0
        private async void LoadRoundProfilePicture(
            String UserId
            )
        {
            PropertySet parameters = new PropertySet();
            String path = "/" + UserId + "/picture";

            parameters.Add(new KeyValuePair<String, Object>("redirect", "false"));

            // Just picking a width and height for now
            parameters.Add(new KeyValuePair<String, Object>("width", "200"));
            parameters.Add(new KeyValuePair<String, Object>("height", "200"));

            FBSingleValue value = new FBSingleValue(path, parameters, 
                new FBJsonClassFactory(FBProfilePicture.FromJson));

            FBResult result = await value.GetAsync();
            if (result.Succeeded)
            {
                FBProfilePicture pic = (FBProfilePicture)result.Object;
                ProfilePicBrush.ImageSource = new BitmapImage(new Uri(pic.Url));
            }
        }
Esempio n. 31
0
        private async Task<string> getAppToken()
        {
            PropertySet parameters = new PropertySet();
            string result = null;
 
            parameters.Add("request_host", FBSDKTokenServiceHost);
            parameters.Add("access_token", "");
            parameters.Add("id", TestAppId);
            
            FBSingleValue sval = new FBSingleValue(FBSDKTokenApiPath,
                parameters, 
                new FBJsonClassFactory((JsonText) => 
            {
                JsonObject obj = null;
                if (!JsonObject.TryParse(JsonText, out obj))
                {
                    obj = null;
                }

                return obj;
            }));

            FBResult fbresult = await sval.GetAsync();

            if (fbresult.Succeeded)
            {
                JsonObject obj = (JsonObject)fbresult.Object;
                if (obj.Keys.Contains("access_token"))
                { 
                    result = obj.GetNamedString("access_token"); 
                }
            }

            return result;
        }
Esempio n. 32
0
        public async void makeGraphRequest(
            string path,
            JObject parameters,
            string version,
            string method,
            IPromise promise)
        {
            if (version != null)
            {
                throw new NotSupportedException("Version parameter is not currently supported.");
            }

            var propertySet = new PropertySet();
            foreach (var pair in parameters)
            {
                propertySet.Add(pair.Key, pair.Value);
            }

            var request = new FBSingleValue(path, propertySet, s_jsonFactory);
            var result = await ExecuteAsync(method, request);
            if (result.Succeeded)
            {
                promise.Resolve(result.Object);
            }
            else
            {
                promise.Reject(result.ErrorInfo.Message);
            }
        }
Esempio n. 33
0
        public async Task<FBResult> deleteTestUser(
            FBTestUser user
            )
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();
            string path = "/" + user.Id;

            parameters.Add("access_token", Uri.EscapeUriString(token));

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBSuccess.FromJson));

            return await sval.DeleteAsync();
        }
Esempio n. 34
0
        public async Task<FBResult> publishCustomUserObject(
            FBTestUser user
            )
        {
            PropertySet parameters = new PropertySet();
            string path = user.Id + "/objects/logincs:noun";

            Assert.IsNotNull(user.AccessToken);
            parameters.Add("access_token", user.AccessToken);
            parameters.Add("object", FBCustomObjectInstance);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            return await sval.PostAsync();
        }
Esempio n. 35
0
        public async Task testLikeSomething()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions",
                "public_profile,publish_actions,user_photos");

            FBTestUser user = await createTestUser(parameters);

            string path = user.Id + "/og.likes";

            // Because *everybody* likes these, amirite?
            string likedObject =
                Uri.EscapeUriString("http://en.wikipedia.org/wiki/Brussels_sprout");

            parameters.Add("object", likedObject);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            FBResult result = await sval.PostAsync();
            Assert.IsTrue(result.Succeeded);

            try
            {
                FBObject like = (FBObject)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                    "expected type (FBObject).");
            }
        }
Esempio n. 36
0
        public async Task testUploadPhoto()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", Uri.EscapeUriString(token));
            parameters.Add("permissions", FBTestPhotoUploadPermissions);

            FBTestUser user = await createTestUser(parameters);

            StorageFolder appFolder = 
                Windows.ApplicationModel.Package.Current.InstalledLocation;
            StorageFile f = await appFolder.GetFileAsync(
                FBTestImagePath);
            IRandomAccessStreamWithContentType stream = await f.OpenReadAsync();
            Assert.IsNotNull(stream);

            FBMediaStream fbStream = new FBMediaStream(FBTestImageName, 
                stream);

            // Switch to user access token to post photo.
            parameters.Remove("access_token");
            parameters.Add("access_token", user.AccessToken);

            parameters.Add("source", fbStream);

            string path = "/" + user.Id + "/photos";

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBPhoto.FromJson));

            FBResult result = await sval.PostAsync();
            Assert.IsTrue(result.Succeeded);

            try
            {
                FBPhoto pic = (FBPhoto)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsFalse(true, "Object returned was not of the " +
                    "expected type (FBPhoto).");
            }
        }
Esempio n. 37
0
        public async Task<FBResult> publishCustomStory(
            FBTestUser user,
            FBObject customObject
            )
        {
            PropertySet parameters = new PropertySet();
            string path = user.Id + "/logincs:verb";

            parameters.Add("noun", customObject.Id);
            parameters.Add("access_token", user.AccessToken);

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            return await sval.PostAsync();
        }
Esempio n. 38
0
        private async Task<FBObject> postToFeed(
            FBTestUser User,
            string Message
            )
        {
            PropertySet parameters = new PropertySet();

            parameters.Add("access_token", User.AccessToken);
            parameters.Add("message", Message);

            string path = "/" + User.Id + FBFeedPath;

            FBSingleValue sval = new FBSingleValue(path, parameters,
                new FBJsonClassFactory(FBObject.FromJson));

            FBResult fbresult = await sval.PostAsync();

            return (FBObject)fbresult.Object;
        }
Esempio n. 39
0
 private static IAsyncOperation<FBResult> ExecuteAsync(string method, FBSingleValue request)
 {
     switch (method.ToLowerInvariant())
     {
         case "delete":
             return request.DeleteAsync();
         case "get":
             return request.GetAsync();
         case "post":
             return request.PostAsync();
         default:
             throw new NotSupportedException($"Method '{method}' is not supported.");
     }
 }