2009年9月28日 星期一

Google Calendar Api query constrain

在使用google calendar api 中, 其實有以個預設的查詢限制,

舉例來說,若想要查詢其中一本日曆的事件, 但一次查最多只有25筆
如 : http://www.google.com/calendar/feeds/default/private/full
解果只會傳回最新的25筆資料


但 若要查詢所有的資料的話,可以設定 max-results 的數量, 將他設定一個很大的值
如,可以將url 改為
http://www.google.com/calendar/feeds/default/private/full?max-results=200



見 google 常見問題 How do I retrieve more than 25 results in an event feed?

Google Calendar api in javascript

之前將 google calendar 試過了 .net 和 java 上應用, 現在來試試 javascript 。

在是的過程中發現了幾項限制

1. 必須要架在server 上
可以用 apache 或 iis 的方法, 我這裡是用 eclipse + google app engine 的方式 ,之後在上傳到 google app engine 上

2. 在網頁上要至少放一個圖檔
這個限制有點奇怪,不過不放的話會有一個 「An image of the same domain is required on this page for authenticated reads and all writes.」的錯誤 (參考 Geoffrey's 有人QWERTY絮語 )

之後照者 Google Calendar APIs and Tools 的教學即可

以下是我寫得 範例

2009年9月17日 星期四

Upload image to the picasa web album

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library

這個範例輸入 以下資訊就可以上傳 圖片到picasa,不同於google 官方範例是從檔案路徑讀取檔案在上傳 ,這裡 傳入一個 BitmapImage 即可取得 圖片的資料


註 1、 Image Type
  • image/bmp
  • image/gif
  • image/jpeg
  • image/png
註 2、 Picasa Web Albums Data API - C# delelper's guide

Code 如下





/**
* @Name UpLoadImageToWebAlbum
*
* Upload photo to the the picasa web album,
* In there, using the StreamSource get the photo byte array
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
* @param AlbumUri [in] - the google picasa web album uri
* @param PhotoID [in] - the photo id
* @param Image [in] - the image which want upload
*
*/
public void UpLoadImageToWebAlbum(string Account, string Password, string AlbumUri, String PhotoID, BitmapImage Image)
{


/// Set Service
PicasaService service = new PicasaService("UploadImag");

/// Set Account and Password
service.setUserCredentials(Account, Password);


/// Set Uri
Uri postUri = new Uri(AlbumUri);


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;
IWebProxy iProxy = WebRequest.DefaultWebProxy;
WebProxy myProxy = new WebProxy(iProxy.GetProxy(postUri));

///potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;

myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Insert photo
/// service.Insert(the album uri, image's StreamSource, image type , the image name );
service.Insert(postUri, Image.StreamSource, "image/png", "" + PhotoID);

///Insert Pic

/// Close stream
Image.StreamSource.Close();

MessageBox.Show("OK");



}



Get picasa web album Photo list in album by c#

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library



這個範例輸入 帳號、密碼及 AlbumUri 就可以取得 在這個相簿裡的 所有的photo 資料

註1、 AlbumUri 可以見上一篇 取得的 FeedUri
註2、 entry.Content.AbsoluteUri 就是實際存放相片的位址




/**
* @Name GetPhotoListInAlbum
*
* Get album list from the picasa web album
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
* @param AlbumUri [in] - the google picasa web album uri
*
*/
public void GetPhotoListInAlbum(string Account, string Password, string AlbumUri)
{


/// Set Service
PicasaService service = new PicasaService("Get_Album_List");

/// Set Account and Password
service.setUserCredentials(Account, Password);

/// Set Query
PhotoQuery query = new PhotoQuery(AlbumUri);


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;

IWebProxy iProxy = WebRequest.DefaultWebProxy;

WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));

///potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Get feed
PicasaFeed feed = service.Query(query);


/// Get Album count
int count = feed.Entries.Count;
Console.WriteLine(count);


foreach (PicasaEntry entry in feed.Entries)
{
/// Get album title
string title = entry.Title.Text;
Console.WriteLine(title);

/// Get the image uri
string uri = entry.Content.AbsoluteUri;
Console.WriteLine(uri);
}

}



Get picasa web album list by c#

在 C# 要使用 picasa web album data api , 在下在完 google api 後, 記得 include 以下的 dll

  • Google Data API Access Control Library
  • Google Data API Core Library
  • Google Data API Extansions Library
  • Google Data API Picasa Library
下面這個 例子 就是 輸入 google 帳號和密碼後就可以取得所有的相簿清單

註1 、 其中要注意的就是 query 的用法, 預設 可以使用 "default" 來取得自己的相簿清單
但是可以取代成其他使用者,用這語法來找到你想知道的人的相簿(僅限於他公開或分享給你的)


例如 朋友的帳號為 xxxxx@gmail.com
FriendAccountName = "xxxxx";

語法可以 轉成
AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(FriendAccountName));


註2 、 取得後 entry.FeedUri 可以取得 相簿的 uri 位址, 可利用這個位址取得在這相簿所有的圖片資訊

code 如下




/**
* @Name GetAlbumList
*
* Get album list from the picasa web album
*
* @param Account [in] - the google accpount
* @param Password [in] - the google accpount's password
*
*
*/
public void GetAlbumList(string Account, string Password)
{


/// Set Service
PicasaService service = new PicasaService("Get_Album_List");

/// Set Account and Password
service.setUserCredentials(Account, Password);

/// Set Query , default is the account user,
/// "default" can chang other user name to get other album (if that user set public or share with you)
AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));


/// Set proxy
GDataRequestFactory requestFactory = (GDataRequestFactory)service.RequestFactory;

IWebProxy iProxy = WebRequest.DefaultWebProxy;

WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));

// /potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
requestFactory.Proxy = myProxy;


/// Get feed
PicasaFeed feed = service.Query(query);


/// Get Album count
int count = feed.Entries.Count;
Console.WriteLine(count);


foreach (PicasaEntry entry in feed.Entries)
{
/// Get album title
string title = entry.Title.Text;
Console.WriteLine(title);

/// Get Album feed uri , by this uri can get the photo information in this album
string Uri = entry.FeedUri;
Console.WriteLine(Uri);

}

}