Giter VIP home page Giter VIP logo

chatter-toolkit-for-net's Introduction

Chatter Toolkit for .NET

The Chatter Toolkit for .NET provides an easy way for .NET developers to interact with the Chatter REST API using a native libraries. This toolkit is built using the Async/Await pattern for asynchronous development and .NET portable class libraries, making it easy to target multiple Microsoft platforms, including .NET 4/4.5, Windows Phone 8, Windows 8/8.1, and Silverlight 5.

NuGet Packages

Published Packages

You can try the library immmediately by installing this NuGet package.

Install-Package DeveloperForce.Chatter

DevTest Packages

If you want to use the most recent DevTest NuGet packages you can grab the packages built during the CI build. All you need to do is setup Visual Studio to pull from the build servers NuGet feed:

  1. In Visual Studios select Tools -> Library Package Manager -> Package Manager Settings. Choose Package Sources.
  2. Click + to add a new source.
  3. Change the Name to "Salesforce Toolkits for .NET (DevTest)".
  4. Change the Source to http://dfbuild.cloudapp.net/guestAuth/app/nuget/v1/FeedService.svc/.

Now you can choose to install the latest NuGet from this DevTest feed.

Samples

The toolkit includes the following sample applications.

TBD

Operations

Currently the following operations are supported.

Authentication

To access the Force.com APIs you must have a valid Access Token. Currently there are two ways to generate an Access Token: the Username-Password Authentication Flow and the Web Server Authentication Flow

Username-Password Authentication Flow

The Username-Password Authentication Flow is a straightforward way to get an access token. Simply provide your consumer key, consumer secret, username, and password.

var auth = new AuthenticationClient();

await auth.UsernamePassword("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURUSERNAME", "YOURPASSWORD");

Web-Server Authentication Flow

The Web-Server Authentication Flow requires a few additional steps but has the advantage of allowing you to authenticate your users and let them interact with the Force.com using their own access token.

First, you need to authetnicate your user. You can do this by creating a URL that directs the user to the Salesforce authentication service. You'll pass along some key information, including your consumer key (which identifies your Connected App) and a callback URL to your service.

var url =
    Common.FormatAuthUrl(
        "https://login.salesforce.com/services/oauth2/authorize", // if using test org then replace login with text
        ResponseTypes.Code,
        "YOURCONSUMERKEY",
        HttpUtility.UrlEncode("YOURCALLBACKURL"));

After the user logs in you'll need to handle the callback and retrieve the code that is returned. Using this code, you can then request an access token.

await auth.WebServer("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURCALLBACKURL", code);

You can see a demonstration of this in the following sample application: https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/WebServerOAuthFlow

Creating the ChatterClient

After this completes successfully you will receive a valid Access Token and Instance URL. The Instance URL returned identifies the web service URL you'll use to call the Force.com REST APIs, passing in the Access Token. Additionally, the authentication client will return the API version number, which is used to construct a valid HTTP request.

Using this information, we can now construct our Force.com client.

var instanceUrl = auth.InstanceUrl;
var accessToken = auth.AccessToken;
var apiVersion = auth.ApiVersion;

var client = new ChatterClient(instanceUrl, accessToken, apiVersion);
```

### Sample Code

Below you'll find a few examples that show how to use the toolkit.

#### Get Information About Yourself

You can grab your personal feed with the following code:

```
var me = await chatter.Me<Me>();
```

#### Post to Your Feed

You can easily post to your Chatter feed with the following code:

```
var me = await chatter.Me<Me>();
var id = me.id;

var messageSegment = new MessageSegment()
{
    text = "Testing 1, 2, 3",
    type = "Text"
};

var body = new FeedItemBody { messageSegments = new List<MessageSegment> { messageSegment } };
var feedItemInput = new FeedItemInput()
{
    attachment = null,
    body = body
};

var feedItem = await chatter.PostFeedItem<FeedItem>(feedItemInput, id);
```

#### Comment on a Feed

You can comment on a Chatter feed with the following code:

```
var feedId = feedItem.id;

var messageSegment = new MessageSegment()
{
    text = "Comment testing 1, 2, 3",
    type = "Text"
};

var body = new FeedItemBody { messageSegments = new List<MessageSegment> { messageSegment } };
var commentInput = new FeedItemInput()
{
    attachment = null,
    body = body
};

var comment = await chatter.PostFeedItemComment<Comment>(commentInput, feedId);
```

#### Like a Feed

You can like a Chatter feed with the following code:

```
var feedId = feedItem.id;

var liked = await chatter.LikeFeedItem<Liked>(feedId);
```

chatter-toolkit-for-net's People

Contributors

wadewegner avatar delmerjohnson avatar

Watchers

 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.