Monday, January 20, 2014

MyBlogger or My Blogger

My Blogger is a win phone 8 client for Google Blogger. You can view, update, and delete existing posts as well as creating new posts. The MyBlogger Premium version supports creating new posts that contains images and the images are persisted in the Picasa albums.

Personally, I've been using this app a lot on my phone to blog about my daughter on the silly or memorable things she has done that day. Originally I was using twitter but I got frustrated because of the 140 characters limitation and I struggled with making the gist of the post fit, so I went back to my google blog account.  However I found that there is no good win phone 8 client for it, so I decided to write my own - so viola - MyBlogger.

This has been a fun development exercise for me and I really like doing mobile development. I hope everyone found MyBlogger useful as I have and thank you for using it.

Wednesday, January 8, 2014

Snippet Code to Get OAuth2 token from Google Blogger V3 / Picasa API

string[] scopes = new[] { BloggerService.Scope.Blogger, @"https://picasaweb.google.com/data/" };

// string[] scopes = new[] { BloggerService.Scope.Blogger };

try



{
 
using (var stream = new System.IO.FileStream("client_secrets.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))



{
 
CancellationToken = new CancellationToken();

Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(

GoogleClientSecrets.Load(stream).Secrets,

scopes, //new[] { BloggerService.Scope.Blogger },

"user",

CancellationToken.None);



}
 
string picasaURL = CreatePublicGalleryUrlRequest(Credential.Token.AccessToken);

await GetAlbums(picasaURL);

GetAlbums Picasa API 2.0 Using .NET


Here is a snippet of code from MyBlogger app that gets the list of public Picasa albums in .NET using the Picasa RESTFUL APIs V2.
       
       
public string CreatePublicGalleryUrlRequest(string accessToken)



{
 
string UrlRequest = "https://picasaweb.google.com/data/feed/api/user/default"

+ "?alt=json&v=2&kind=album&access=public&access_token=" + accessToken;

return (UrlRequest); // alt=json&v=2&



}



public async Task GetAlbums(string requestUrl)

{

    try

    {

        AlbumList = new ObservableCollection<AlbumNode>();

               

        // Add the default album location per Picasa documentation

        AlbumNode albumNode = new AlbumNode();

        albumNode.UploadUrl = "https://picasaweb.google.com/data/feed/api/user/default/albumid/default";

        albumNode.FriendlyUrl = albumNode.UploadUrl;

 

        AlbumList.Add(albumNode);

 

        HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;

        request.Method = "GET";

 

        using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)

        {

            if (response.StatusCode != HttpStatusCode.OK)

                throw new Exception(String.Format(

                "Server error (HTTP {0}: {1}).",

                response.StatusCode,

                response.StatusDescription));

            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));

 

            object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());

            Response jsonResponse = objResponse as Response;

 

            if (jsonResponse != null)

            {

                if (jsonResponse.Feed.Entry != null)

                {
                                // Do your thing here
                }

            }

        }

    }

    catch (Exception e)

    {

        string message = string.Format("I am having trouble getting list of picassa public album: {0}", e.ToString());

        ShowErrorMessage(message);

    }

}