利用 Google Data API 访问 Picasa 相册源码(ASP.NET C#)
利用Google Data API访问Picasa相册是件很简单的事,简单不简单看下面源码(只实现了简单的将Album名称列出来):
网页部分源代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Picasa._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title>无标题页</title></head><body><form id="form1" runat="server"><div>用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>密码:<asp:TextBox ID="TextBox2"runat="server" TextMode="Password"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></div></form></body></html>
程序部分源代码:
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Xml.Linq;using Google.GData.Client;using Google.GData.Photos;namespace Picasa{public partial class _Default : System.Web.UI.Page{private Service service = new PicasaService("Picasa");private PicasaService picasaservice = new PicasaService("Picasa");private string authToken;private string user,password;private PicasaFeed picasafeed;protected void Page_Load(object sender, EventArgs e){}void album(string username, string userpass){this.service.setUserCredentials(username, userpass);this.authToken = this.service.QueryAuthenticationToken();//Response.Write(this.authToken);picasaservice.SetAuthenticationToken(this.service.QueryAuthenticationToken());AlbumQuery query = new AlbumQuery();query.Uri = new Uri(PicasaQuery.CreatePicasaUri(this.user));this.picasafeed = this.picasaservice.Query(query);foreach (PicasaEntry entry in this.picasafeed.Entries){Response.Write(entry.Title.Text);Response.Write("<br />");}}protected void Button1_Click(object sender, EventArgs e){this.user = TextBox1.Text;this.password = TextBox2.Text;album(this.user, this.password);}}}
程序写的有点罗嗦,是不是很简单:)
0 comments:
Post a Comment