Code Monkey home page Code Monkey logo

xamarians.facebooksdk's Introduction

Xamarians.FacebookSdk

Cross platform library to allow users to login through facebook account in the app and also retrieves the profile for that particular user.

First install package from nuget using following command -

Install-Package Xamarians.FacebookSdk

You can integrate FacebookSdk in Xamarin Form application using following code:

Shared Code -

Add this to call the facebook sdk functions

       private string GenerateFilePath()
        {
            return Path.Combine(MediaService.Instance.GetPublicDirectoryPath(), MediaService.Instance.GenerateUniqueFileName("jpg"));
        }

        private async void FbSignInClicked(object sender, EventArgs e)
        {
            var result = await DependencyService.Get<IFacebookLogin>().SignIn();
            if (result.Status == Xamarians.FacebookLogin.Platforms.FBStatus.Success)
            {
                await DisplayAlert("Success", "Welcome " + result.Name, "Ok");
            }
            else
            {
                await DisplayAlert("Error", result.Message, "Ok");
            }

        }

        private async void FbSignOutClicked(object sender, EventArgs e)
        {
            var result = await DependencyService.Get<IFacebookLogin>().SignOut();
            if (result.Status == Xamarians.FacebookLogin.Platforms.FBStatus.Success)
            {
                await DisplayAlert("Success", result.Message, "Ok");
            }
            else
            {
                await DisplayAlert("Error", result.Message, "Ok");
            }
        }

        private async void FbImageShareClicked(object sender, EventArgs e)
        {
            DependencyService.Get<IFacebookLogin>().ShareImageOnFacebook("Hi, This is demo text", "image-filePath");
        }

        private void FbTextShareClicked(object sender, EventArgs e)
        {
            DependencyService.Get<IFacebookLogin>().ShareTextOnFacebook("Hi, This is a demo text");
        }

        private void FbLinkShareClicked(object sender, EventArgs e)
        {
            DependencyService.Get<IFacebookLogin>().ShareLinkOnFacebook("your Link", "Hi, this is demo text","http://www.google.com");
        }
        

iOS - in AppDelegate file write below code -

 Xamarians.FacebookLogin.iOS.DS.FacebookLogin.Init();

iOS - Add following permissions in the info.plist

	<key>CFBundleVersion</key>
	<string>1.0</string>
	<key>FacebookAppID</key>
	<string>your-facebook-id</string>
	<key>FacebookDisplayName</key>
	<string>your-app-name</string>
	<key>LSApplicationQueriesSchemes</key>
	<array>
		<string>fbapi</string>
		<string>fb-messenger-api</string>
		<string>fbauth2</string>
		<string>fbshareextension</string>
		<string>fb</string>
	</array>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>fb[facebookid]</string>
			</array>
		</dict>
	</array>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>

Android - in Mainactivity file write the below code

Xamarians.FacebookLogin.Droid.DS.FacebookLogin.Init("your-facebook-app-id");

Add the following permissions in Android Manifest file

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  

Add the following in the Application tag in Android Manifest file

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="your-facebook-app-id" />
<activity android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="Facebook Login" android:name="com.facebook.FacebookActivity" />
<provider android:authorities="com.facebook.app.FacebookContentProvider[your-facebook-app-id]" android:name="com.facebook.FacebookContentProvider" android:exported="true" />
    

xamarians.facebooksdk's People

Contributors

xamarians avatar kartik-parashar avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.