Exemplo n.º 1
0
        private async Task <Dictionary <string, string> > LocalQuery(AccessToken token, string query)
        {
            var parameters = new Bundle();

            parameters.PutString("fields", "id,name,email,location");

            var request = new GraphRequest(token, query, parameters, HttpMethod.Get);

            try
            {
                var graphREsponse = await Task.Run(() => request.ExecuteAndWait());

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

                var email    = graphREsponse.JSONObject.GetString("email");
                var name     = graphREsponse.JSONObject.GetString("name");
                var location = graphREsponse.JSONObject.GetJSONObject("location").GetString("name");
                return(new Dictionary <string, string>
                {
                    { "email", email },
                    { "name", name },
                    { "location", location }
                });
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            return(null);
        }
Exemplo n.º 2
0
        private void Btn_Click(object sender, EventArgs e)
        {
            LoginManager.Instance.LogOut();
            LoginManager.Instance.LogIn(this, PERMISSIONS);

            Task.Run(() =>
            {
                var likesRequest = "Insert_Requred_Request_To_Get_Likes_Info";
                var response     = GraphRequest.ExecuteAndWait(new GraphRequest(AccessToken.CurrentAccessToken, likesRequest));
                //ToDo: process response, get FB likes
                if (response != null && response.JSONObject is Org.Json.JSONObject jSON)
                {
                    var likes = jSON.GetInt("Here_Goes_The_Name_Of_Parameter");
                }
            });
        }
 Task LogIn()
 {
     return(Task.Run(() =>
     {
         var session = Xamarin.Facebook.AccessToken.CurrentAccessToken;
         if (session != null)
         {
             var request = new GraphRequest(session, "me");
             var response = request.ExecuteAndWait();
             var id = response.JSONObject.GetString("id");
             var name = response.JSONObject.GetString("name");
             Device.BeginInvokeOnMainThread(() =>
             {
                 Element.SendShowingLoggedInUser(
                     new FacebookUser(id, session.Token, name, name, name, string.Format("http://graph.facebook.com/{0}/picture?type=large", id))
                     );
             });
         }
     }));
 }