https://github.com/bluechilli/chillisource.mobile.facebook
Facebook identity plugin for ChilliSource Mobile
https://github.com/bluechilli/chillisource.mobile.facebook
android csharp dotnet ios xamarin xamarin-forms
Last synced: about 2 months ago
JSON representation
Facebook identity plugin for ChilliSource Mobile
- Host: GitHub
- URL: https://github.com/bluechilli/chillisource.mobile.facebook
- Owner: BlueChilli
- License: mit
- Created: 2017-05-01T06:59:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-08T07:05:33.000Z (about 8 years ago)
- Last Synced: 2025-08-01T07:59:56.532Z (10 months ago)
- Topics: android, csharp, dotnet, ios, xamarin, xamarin-forms
- Language: C#
- Size: 47.9 KB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/MIT) 
# ChilliSource.Mobile.Facebook #
This project is part of the ChilliSource framework developed by [BlueChilli](https://github.com/BlueChilli).
## Summary ##
```ChilliSource.Mobile.Facebook``` provides simplified access to Facebook's identity and media sharing features.
## Usage ##
### Identity ###
To use Facebook's login and identity functionality, first initialize the ```ChilliSource.Mobile.Facebook.IIdentityService``` dependency service:
```csharp
var identityService = DependencyService.Get();
```
You must also add the following code to your ```AppDelegate.cs``` for iOS:
```csharp
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 work.
return ApplicationDelegate.SharedInstance.OpenUrl(application, url, sourceApplication, annotation);
}
```
**Logging In**
```csharp
var permissions = { "public_profile", "email" };
var fields = { "id", "name", "email", "gender", "age_range", "first_name", "last_name",
"is_verified", "verified", "picture" };
var result = await identityService.Login(fields, permissions);
if (result.IsSuccessful)
{
var token = result.Result.Token;
Console.WriteLine("Facebook token: " + token);
}
```
This will present the standard Facebook login page and return back to the application once the user has logged in.
**Logging Out**
```csharp
identityService.Logout();
```
**Retrieving User Info**
```csharp
var userInfoResult = await Global.Instance.FacebookIdentityProvider.GetUserInfo(token, fields);
if (userInfoResult.IsSuccessful)
{
JObject data = userInfoResult.Result.Data;
var name = data["name"].ToString();
var facebookId = data["id"].ToString();
}
```
### Sharing ###
To use Facebook's media sharing functionality, first initialize the ```ChilliSource.Mobile.Facebook.ISharingService``` dependency service:
```csharp
var sharingService = DependencyService.Get();
```
Invoking any of the sharing methods below will present a Facebook popup prompting the user to share the specified link/video/images.
**Sharing a Link**
```csharp
var result = sharingService.ShareLink(linkUrl, hashtags);
```
**Sharing Images**
You can share multiple images at the same time by passing in a List of string paths.
```csharp
var result = sharingService.ShareImageFiles(imagePaths, hashtags);
```
Note that the image paths have to point to assets in the media library. Use the ```ChilliSource.Mobile.Media.IMediaService``` dependency service to retrieve the media library url for an asset.
**Sharing a Video**
```csharp
var result = sharingService.ShareVideoFile(videoPath, hashtags);
```
Note that the video path has to point to an asset in the media library. Use the ```ChilliSource.Mobile.Media.IMediaService``` dependency service to retrieve the media library url for an asset.
### Analytics ###
To use Facebook's ```AppEvents``` to log analytics data, first initialize the ```ChilliSource.Mobile.Facebook.IAppEventsService``` dependency service:
```csharp
var appEventsService = DependencyService.Get();
```
Then add the following code in your ```AppDelegate.cs``` for iOS:
```csharp
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
...
if (options == null || options[UIApplication.LaunchOptionsUrlKey] == null)
{
var result = await appEventsService.FetchDeferredAppLink();
if (result.IsSuccessful)
{
UIApplication.SharedApplication.OpenUrl(NSUrl.FromString(result.Result));
}
}
...
}
```
```csharp
public override void OnActivated(UIApplication uiApplication)
{
appEventsService?.ActivateApp();
}
```
To log custom events simply call:
```csharp
appEventsService.LogEvent(eventTitle);
```
## Installation ##
The library is available via NuGet [here](https://www.nuget.org/packages/ChilliSource.Mobile.Api).
## Releases ##
See the [releases](https://github.com/BlueChilli/ChilliSource.Mobile.Facebook/releases).
## Contribution ##
Please see the [Contribution Guide](.github/CONTRIBUTING.md).
## License ##
ChilliSource.Mobile is licensed under the [MIT license](LICENSE).
## Feedback and Contact ##
For questions or feedback, please contact [chillisource@bluechilli.com](mailto:chillisource@bluechilli.com).