public GraphUser GetFriend(decimal id) { string accessToken = NSUserDefaults.StandardUserDefaults.StringForKey("FacebookAccessToken"); NSDate expirationDate = (NSDate)NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString("FacebookExpirationDate")); if (!string.IsNullOrEmpty(accessToken) && expirationDate!=null) { var url = string.Format("https://graph.facebook.com/{0}?access_token={1}&format=json", id, accessToken); var request = WebRequest.Create(url) as HttpWebRequest; try { using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { var reader = new StreamReader(response.GetResponseStream()); string str = reader.ReadToEnd(); Dictionary<string, string> dict = GetJsonDict(str); if (dict.ContainsKey("name")) { var gUser = new GraphUser() { name = dict["name"], id = id, }; return gUser; } } } catch (Exception ex) { Util.LogException("GetFriend", ex); } } return null; }
/* public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); } */ public override void Draw (RectangleF bounds, CGContext context, UIView view) { UIColor.White.SetFill (); context.FillRect (bounds); RectangleF frame = _inviteButton.Frame; frame.X = view.Frame.Width - frame.Width - 10; _inviteButton.Frame = frame; view.Add(_inviteButton); if (userImage != null) { //context.DrawImage(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35), userImage.CGImage); userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35)); } if (graph.ContainsKey(_User.id)) _User = graph[_User.id]; UIColor.Black.SetColor (); if (_User.name != null) { view.DrawString(_User.name, new RectangleF(50, 5, bounds.Width/2, 10 ), fromFont, UILineBreakMode.TailTruncation); if (userImage == null) { userImage = ImageStore.RequestFullPicture((long)_User.id, (long)_User.id, SizeDB.SizeFacebook, this); userImage = userImage ?? ImageStore.EmptyProfileImage; userImage = UIImageUtils.resizeImage(userImage, new SizeF (35, 35)); userImage = GraphicsII.RemoveSharpEdges(userImage); if (userImage != null) userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35)); } } else { ThreadPool.QueueUserWorkItem(o => { GraphUser gUser = AppDelegateIPhone.AIphone.FacebookServ.GetFriend(_User.id); if (gUser == null) return; lock (lock_graph) { graph[gUser.id] = gUser; } if (gUser.id == _User.id) { _User = gUser; nss.InvokeOnMainThread(()=> view.SetNeedsDisplay()); } }); } }
public FbUserElement(GraphUser user, Action<string> openUrl) : base(UITableViewCellStyle.Value1, "FbUserElement", UITableViewCellSelectionStyle.None, UITableViewCellAccessory.None) { _openUrl = openUrl; _User = user; _inviteButton = UIButton.FromType (UIButtonType.RoundedRect); _inviteButton.Frame = new RectangleF(0, (_height - 30)/2, 60, 30); _inviteButton.SetTitleColor(UIColor.LightGray, UIControlState.Normal); _inviteButton.SetTitle("invite", UIControlState.Normal); _inviteButton.TouchDown += Handle_inviteButtonTouchDown; }
public void LoadFacebookFriends() { var facebookApp = new FaceBook.FaceBookApplication(this); if (!facebookApp.LoggedIn()) { InvokeOnMainThread(()=> { var soc = new SocialNetworksParentViewController(_MSP); _MSP.PushViewController(soc, true); }); return; } List<Decimal> friends = AppDelegateIPhone.AIphone.FacebookServ.GetFriends(); if (friends == null) { Util.LogException("friends", new Exception()); return; } var socialIds = new List<long>(); foreach (decimal d in friends) { socialIds.Add((long)d); } var fBresp = AppDelegateIPhone.AIphone.UsersServ.GetSocialIds(socialIds, 1); List<User> facebookFriends = fBresp.Subscribers; if (facebookFriends == null) { Util.LogException("facebookFriends", new Exception()); return; } if (facebookFriends.Count == 0) { InvokeOnMainThread(()=> { var alert = new UIAlertView("Search", "No facebook friend found", null, "Ok"); alert.Show(); }); return; } facebookApp = new FaceBook.FaceBookApplication (this); InvokeOnMainThread(()=> { var root = new RootElement("") { new Section() }; var dv = new DialogViewController(root, true); foreach (User fuser in facebookFriends) { var user = new UserElementII(fuser, RelationType.Friends); root[0].Add(user); } foreach (long socialId in fBresp.Others) { var guser = new GraphUser() { id = socialId }; var fbUser = new FbUserElement(guser, u => { WebViewController.OpenUrl (dv, "https://www.facebook.com/dialog/apprequests?app_id=168889879843414&message=Welcome to 21Off!&redirect_uri=http://www.21off.net"); }); root[0].Add(fbUser); } var ev = new EmptyViewController(() => _MSP.PopViewControllerAnimated(true), "Facebook friends"); dv.TableView.BackgroundView = new UIImageView(UIImage.FromBundle("Images/Ver4/fond")); dv.View.Frame = new RectangleF(0, 40, 320, 480 - 40); ev.Add(dv.View); _MSP.PushViewController(ev, false); }); }
public void Login() { //_facebook.Authorize(new string[]{"publish_stream", "offline_access"}, _sessionDelegate); var socialLogin = new SocialLogin.SocialLogin(new SocialLogin.FacebookConfig(){ AppID = _appId, Permissions = new string[] { "publish_stream" } }); socialLogin.LoginComplete += delegate(SocialLogin.SocialLogin sender) { Console.WriteLine("Logged in as " + sender.Username); _facebook.AccessToken = sender.AccessToken; _facebook.ExpirationDate = sender.ExpirationDate; GraphUser guser = null; decimal id; if (decimal.TryParse(sender.UserId, out id)) { guser = new GraphUser() { id = id, name = sender.Username, }; } SaveSessionData(true); if (OnLoginComplete != null) OnLoginComplete(); if (OnExtraLoginComplete != null) OnExtraLoginComplete(guser); }; socialLogin.LoginFailure += delegate { Console.WriteLine("Login failure"); SaveSessionData(false); if (OnLoginComplete != null) OnLoginComplete(); if (OnExtraLoginComplete != null) OnExtraLoginComplete(null); }; socialLogin.Login(_parentViewController, true); }