Skip to content

Instantly share code, notes, and snippets.

@aspyct
Created April 28, 2016 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspyct/344efd0461252e7c2dad6c74fa369ea3 to your computer and use it in GitHub Desktop.
Save aspyct/344efd0461252e7c2dad6c74fa369ea3 to your computer and use it in GitHub Desktop.
Share on facebook page with Xamarin (Requires "Facebook iOS SDK component")
using Facebook.CoreKit;
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
// Override point for customization after application launch.
// If not required for your application you can safely delete this method
return ApplicationDelegate.SharedInstance.FinishedLaunching (application, launchOptions);
}
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
// We need to handle URLs by passing them to their own OpenUrl in order to make the SSO authentication works.
return ApplicationDelegate.SharedInstance.OpenUrl (application, url, sourceApplication, annotation);
}
namespace socialtest.iOS
{
public partial class ViewController : UIViewController
{
int count = 1;
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
Button.SetTitle("Login with facebook", UIControlState.Normal);
Button.AccessibilityIdentifier = "myButton";
Button.TouchUpInside += delegate {
var loginManager = new LoginManager();
var permissions = new string[] { "publish_actions" };
loginManager.LogInWithPublishPermissions(permissions, this, (result, errors) => {
// TODO Show success
});
};
publish_button.TouchUpInside += delegate {
var parameters = new NSDictionary("message", "This is a test message from Xamarin");
var request = new GraphRequest("/<page_id>/feed", parameters, "POST");
request.Start(delegate(GraphRequestConnection connection, NSObject result, NSError error) {
if (error != null) {
Console.WriteLine("Failed: " + error);
}
});
};
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment