Automated access_token grant using Facebook and C=
Say you wanted to get an access token for facebook from a desktop app, but don’t want to display the normal facebook login screen. – and you somehow know the user’s facebook username and password – then this approach might help you get the access token you need;
first, you need to set up a facebook app, and get the client_id
public void GetAccessToken(Action<string,string> Callback)
{
this.Callback = Callback;
string strUrl = “https://www.facebook.com/dialog/oauth?”;
strUrl += “type=user_agent&”;
strUrl += “client_id=xxxx&”;
strUrl += “redirect_uri=xxxxx”;
this.webBrowser1.DocumentCompleted += WebBrowser1OnDocumentCompleted;
this.webBrowser1.Navigate(strUrl);
}
Here, I’m assuming you have a windows form, with a web browser control called webBrowser1 – redirect_uri has to be whatever was configured in the facebook app, but other than that, it doesn’t matter.
then we fill out the username / password and click the login burron on Document completed;
private void WebBrowser1OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs webBrowserDocumentCompletedEventArgs)
{
if (webBrowser1.Url.Host == “<domain>”)
{
var variables = HttpUtility.ParseQueryString(webBrowser1.Url.Fragment);
var access_token = variables[“#access_token”];
var expires_in = variables[“expires_in”];
Callback(access_token, expires_in);
}
else
{
var strJs1 = @”document.getElementsByName(’email’)[0].value ='” + strUsername + “‘”;
var strJs2 = @”document.getElementsByName(‘pass’)[0].value = ‘” + strPassword + “‘”;
var strJs3 = @”document.getElementsByName(‘login’)[0].click()”;
SendJs(strJs1);
SendJs(strJs2);
SendJs(strJs3);
}
}
SendJS is defined as follows;
protected string SendJs(string jScript)
{
object[] args = { jScript };
var strReturn = webBrowser1.Document == null ? “” : webBrowser1.Document.InvokeScript(“eval”, args);
System.Diagnostics.Debug.WriteLine(jScript);
System.Diagnostics.Debug.WriteLine(strReturn);
return strReturn == null ? “” : strReturn.ToString();
}
You’ll also need the following global variables
public string strUsername = “<email>”;
public string strPassword = “<password>”;public Action<string, string> Callback;
Hope this helps someone out!
Changes to Linkedin API
|
||||||||||
|
|
||||||||||
|
Using Html5 geolocation to find someone via their email
Here’s a tool that you can use to track the location (lat/lon) of someone via their email account:
Offline Adverts.com – an advertising solution that works even when offline.

Offline Adverts.com is an advertising platform for apps that is designed to work specifically when the user’s device is offline, and not connected to the Internet. This is where most ad platforms just show an empty space, this backup solution allows you to fill that unused ad space with a paid ad.
As an advertiser, it lets you gain brand exposure, even for a fraction of the cost of the mainstream ad networks.
Want to find out more? visit – OfflineAdverts.com
Open Native Google Maps App from Phonegap / Cordova (iOS)
If you want to show a map in your Phonegap app, you can always use the google maps API to show a map, or even use the in-app browser to link out to a google map page. But nothing quite matches the Google maps native app, with it’s funky satnav-like features, and slick interface
Thing is, the Google Maps App isn’t installed by default, so in this case, I’m failing-over to a in-App Browser version. This code is iOS only, but anyone wishing to provide a port to Android will be rewarded* (Yes, I’d pay for the port)
– (void) openGoogleMaps:(CDVInvokedUrlCommand *)command
{
NSLog(@”openGoogleMaps”);
NSString* callbackId = [command callbackId];
NSArray* arguments = [command arguments];
NSString* map = [arguments objectAtIndex:0];
CDVPluginResult* result;
NSURL *testURL = [NSURL URLWithString:@”comgooglemaps://”];
if ([[UIApplication sharedApplication] canOpenURL:testURL]) {
NSString *directionsRequest = [NSString stringWithFormat:@”%@%@”,
@”comgooglemaps://?” ,
map];
NSURL *directionsURL = [NSURL URLWithString:directionsRequest];
[[UIApplication sharedApplication] openURL:directionsURL];
result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:true];
} else {
NSLog(@”Can’t use comgooglemaps:// on this device.”);
result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsBool:false];
}
[self success:result callbackId:callbackId];
}
Then, this is called from Javascript as follows:
function openGoogleMaps(route)
{
console.log(“openGoogleMaps”);
cordova.exec(function(data)
{
console.log(“Returned from google maps:” + data);
if (!data)
{
// Failed to find native app.
var strUrl = “http://maps.google.com/maps?”;
strUrl += route;
var ref = window.open(strUrl, “_blank”, “location=yes”);
}
}, function(data)
{
console.log(“Plugin failure”);
}, ‘StatusBar’, ‘openGoogleMaps’, [route]);
}
Upload a file to Amazon S3 using C#
This code example is probably online a million times, but just to include it again here;
string existingBucketName = “mybucket”;
string filePath = @”c:\users\you\desktop\file.png”;
Amazon.Util.ProfileManager.RegisterProfile(“test”, “xxxxx”,”XXXX”);
AWSCredentials credentials = new StoredProfileAWSCredentials(“test”);
IAmazonS3 s3Client = new AmazonS3Client(credentials, RegionEndpoint.EUWest1);
TransferUtility fileTransferUtility = new TransferUtility(s3Client);
var uploadRequest = new TransferUtilityUploadRequest
{FilePath = filePath,
BucketName = existingBucketName,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(uploadRequest);
Capture hi-res image from iTunes using C#
This is a quick demo of how to use the iTunes API to extract the hi-res icon of any iOS app;
WebClient wc = new WebClient();
string strUrl = @”http://itunes.apple.com/search?term=” + HttpUtility.UrlEncode(tbSearch.Text) + “&entity=iPadSoftware”;
string strHtml = wc.DownloadString(strUrl);
const string strArtRegex = “artworkUrl100.:\”(.*?)\””;
Match mArt = Regex.Match(strHtml, strArtRegex);
string Url = mArt.Groups[1].Value;
imgArtwork.Src = Url;
This assumes a user interface somewhat like this:
<asp:TextBox runat=”server” ID=”tbSearch”></asp:TextBox>
<asp:Button runat=”server” ID=”btnSearch” OnClick=”btnSearchClick” Text=”Search”/>
<br/>
<img id=”imgArtwork” runat=”server”/>
Hope this helps someone.
Favourite Tweets using C# Tweetsharp
If you want to make noise on twitter, favouriting people’s tweets does draw a little attention, so I decided to try to do this automatically, to see if I could build followers.- Here is the code I used in C# (authentication details removed) – you need a reference to TweetSharp
var service = new TwitterService(“########”, “######”);
service.AuthenticateWith(“###”, “#####”);
TwitterSearchResult res = service.Search(new SearchOptions { Q = args[0], Count = 100});
IEnumerable<TwitterStatus> status = res.Statuses;
foreach (var tweet in status)
{
Console.WriteLine(tweet.Text);
service.FavoriteTweet(new FavoriteTweetOptions{Id = tweet.Id});
}
It takes a command line argument, which it uses as a search term, so you can favourite tweets that are relevant.
And, hey if you want to follow me, please go to: https://twitter.com/webtropy
2014 in review
The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.
Here’s an excerpt:
The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 50,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 19 sold-out performances for that many people to see it.
Read extended properties of a file in C#
You need to make a reference to the COM library “Microsoft Shell controls and automation”
[STAThread]
public static void Main(string[] args)
{
List<string> arrHeaders = new List<string>();
Shell32.Shell shell = new Shell32.Shell();
var strFileName = @”C:\Users\Fiach\Desktop\sample_iTunes.mov”;
Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));
for (int i = 0; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}
for (int i = 0; i < arrHeaders.Count; i++)
{
Console.WriteLine(“{0}\t{1}: {2}”, i, arrHeaders[i], objFolder.GetDetailsOf(folderItem, i));
}
Console.ReadLine();
}

