MVC 3和谷歌联系人API [英] MVC 3 and Google Contacts API

查看:196
本文介绍了MVC 3和谷歌联系人API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图拉下人员名单在MVC 3谷歌邮件联系人使用此API:的的http://$c$c.google.com/apis/contacts/
http://$c$c.google.com/apis/contacts/docs/3.0/developers_guide_dotnet.html#Retrieving

I'm trying to pull down a list of a persons Google Mail contacts in MVC 3 using this API: http://code.google.com/apis/contacts/ http://code.google.com/apis/contacts/docs/3.0/developers_guide_dotnet.html#Retrieving

我需要在哪里执行时,它开始帮助。我已经通过的文​​件多次读取,但它只是不是我做的感觉。

I need help with where to start when implementing it. I've read through the documentation numerous times, but it's just not making sense to me.

我要拉下所有的联系人,并显示他们在我的联系人控制器的索引行为。

I want to pull down all the contacts and display them in the Index action of my Contacts Controller.

这个广泛的问题,任何帮助将是很大的AP preciated。

Any help with this broad question would be greatly appreciated.

推荐答案

首先得到一些样本code从上面的工作(编辑 - 见下文实际上)
然后创建一个含有你想显示什么领域一个新的视图模型。
创建这个视图模型一个强类型的视图 ContactsViewModel 的列表(无论你怎么称呼它),这样你的视图顶部的:
@model IEnumerable的< ContactsViewModel>

First get some sample code working from the above (EDIT - see below actually) Then create a new ViewModel with whatever fields in it you want to display. Create a strongly typed view for this ViewModel as a List of ContactsViewModel (whatever you call it) such that at the top of your view its: @model IEnumerable<ContactsViewModel>

创建一个路由到一个URL指向您的控制器的方法,那么在你的方法简单地从谷歌查询,并使用循环,LINQ(或automapper等),你的 ContactsViewModel ,模型回归的看法。

Create a route to point a URL to your controller's method, then in your method simply query from google, and populate using a loop, LINQ, (or automapper, etc) your ContactsViewModel, and return the model to the view.

如果你有一些最重要的是更具体的,让我知道,我会更深入。

If you have something more specific on top of that let me know and I'll go deeper

有他们的同code一些不正确命名/格式化项目具有讽刺意味的​​:)
当然下面添加从C(联系人,客户,扩展)引用:\\ Program Files文件\\谷歌\\谷歌数据API的 SDK \\的Redist 的文件夹

There are some improperly named /formatted items in their same code ironically : ) of course add the references below (contacts, client, extensions) from the C:\Program Files\Google\Google Data API SDK\Redist folder


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.Contacts;


namespace GoogleTests
{
    class Program
    {
        static void Main(string[] args)
        {

            RequestSettings rs = new RequestSettings("myApplication", "youraccount@gmail.com", "yourpwd");
            // AutoPaging results in automatic paging in order to retrieve all contacts

            rs.AutoPaging = true; 
            ContactsRequest cr = new ContactsRequest(rs);

            Feed<Contact> f = cr.GetContacts();
            foreach (Contact entry in f.Entries)
            {
                if (entry.Name != null)
                {
                    Name name = entry.Name;
                    if (!string.IsNullOrEmpty(name.FullName))
                        Console.WriteLine("\t\t" + name.FullName);
                    else
                        Console.WriteLine("\t\t (no full name found)");
                    if (!string.IsNullOrEmpty(name.NamePrefix))
                        Console.WriteLine("\t\t" + name.NamePrefix);
                    else
                        Console.WriteLine("\t\t (no name prefix found)");
                    if (!string.IsNullOrEmpty(name.GivenName))
                    {
                        string givenNameToDisplay = name.GivenName;
                        if (!string.IsNullOrEmpty(name.GivenNamePhonetics))
                            givenNameToDisplay += " (" + name.GivenNamePhonetics + ")";
                        Console.WriteLine("\t\t" + givenNameToDisplay);
                    }
                    else
                        Console.WriteLine("\t\t (no given name found)");
                    if (!string.IsNullOrEmpty(name.AdditonalName))
                    {
                        string additionalNameToDisplay = name.AdditonalName;
                        if (string.IsNullOrEmpty(name.AdditionalNamePhonetics))
                            additionalNameToDisplay += " (" + name.AdditionalNamePhonetics
                      + ")";
                        Console.WriteLine("\t\t" + additionalNameToDisplay);
                    }
                    else
                        Console.WriteLine("\t\t (no additional name found)");
                    if (!string.IsNullOrEmpty(name.FamilyName))
                    {
                        string familyNameToDisplay = name.FamilyName;
                        if (!string.IsNullOrEmpty(name.FamilyNamePhonetics))
                            familyNameToDisplay += " (" + name.FamilyNamePhonetics + ")";
                        Console.WriteLine("\t\t" + familyNameToDisplay);
                    }
                    else
                        Console.WriteLine("\t\t (no family name found)");
                    if (!string.IsNullOrEmpty(name.NameSuffix))
                        Console.WriteLine("\t\t" + name.NameSuffix);
                    else
                        Console.WriteLine("\t\t (no name suffix found)");
                }
                else
                    Console.WriteLine("\t (no name found)");

                foreach (EMail email in entry.Emails)
                {
                    Console.WriteLine("\t" + email.Address);
                }
            }
        }
    }
}

这篇关于MVC 3和谷歌联系人API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆