Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
#oAuthTwitterWrapper
# oAuthTwitterWrapper

This provides a really simple solution to authenticating and wrapping twitter's API calls using the 1.1 API and OAuth.

##Quick installation instructions:
## Quick installation instructions:

Run the following nuget command from your project to install the [package] (http://nuget.org/packages/oAuthTwitterWrapper/):

`Install-Package oAuthTwitterWrapper`
```powershell
Install-Package oAuthTwitterWrapper
```

Amend the appsettings to add your consumer key, secret and screen name. [Generate your key and secret here] (https://dev.twitter.com/apps/new)

Add the following code to return the raw json:

var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
twit.GetMyTimeline();
```c#
var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
twit.GetMyTimeline();
```

If you would prefer to use serialiazed C# pocos use the following:

var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
var json = twit.GetMyTimeline();
var tweets = JsonConvert.DeserializeObject<List<TimeLine>>(json); // Deserialize with Json.NET
```c#
var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
var json = twit.GetMyTimeline();
var tweets = JsonConvert.DeserializeObject<List<TimeLine>>(json); // Deserialize with Json.NET
```

# Notes

#Notes
Currently it exposes timeline (twitter feed) and search calls, returned as raw json (which can be serialized into c# pocos, examples in the github project).

Screen shot below (please note there is no styling applied you have full control over how it is rendered in your application).
Expand Down Expand Up @@ -57,29 +65,32 @@ Amend the appsettings to add your consumer key, secret and screen name. [Generat

Create a macro script with the following code that outputs the json inline to the page:

@using System
@{
var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
var json = twit.GetMyTimeline();
}
```c#
@using System
@{
var twit = new OAuthTwitterWrapper.OAuthTwitterWrapper();
var json = twit.GetMyTimeline();
}

<div id="results"></div>
<script type="text/javascript">
var json = @Html.Raw(json);
</script>
```

<div id="results"></div>
<script type="text/javascript">
var json = @Html.Raw(json);
</script>

Add a reference to jQuery and twitter-text, then add some javascript to parse the json (The code here is just used for example purposes and not best practice):

for (var i = 0; i < json.length; i++) {
$("#results").append('<p><strong> - ' + json[i].created_at.substring(0, 16) + '</strong><br/>' + twttr.txt.autoLink(json[i].text) + '</p>');
try {
for (var j = 0; j < json[i].entities.media.length; j++) {
$("#results").append('<a href="' + json[i].entities.media[j].media_url + '" ><img src="' + json[i].entities.media[j].media_url + ':thumb" /></a>');
}

} catch(e) {
}
}

```c#
for (var i = 0; i < json.length; i++) {
$("#results").append('<p><strong> - ' + json[i].created_at.substring(0, 16) + '</strong><br/>' + twttr.txt.autoLink(json[i].text) + '</p>');
try {
for (var j = 0; j < json[i].entities.media.length; j++) {
$("#results").append('<a href="' + json[i].entities.media[j].media_url + '" ><img src="' + json[i].entities.media[j].media_url + ':thumb" /></a>');
}

} catch(e) {
}
}
```
Add the macro to the template or content within Umbraco.