I have the following code which retrieve contacts.

               if (Scope == String.Empty)
                    Scope = "https://www.google.com/m8/feeds";;
 
                parameters = new OAuthParameters();
                parameters.ConsumerKey = ConsumerKey;
                parameters.ConsumerSecret = ConsumerSecret;
                parameters.Scope = Scope;
                parameters.Callback = OAuthCallback;
                parameters.SignatureMethod = SignatureMethod;
                parameters.Timestamp = Toolbox.GenerateTimeStamp();
                parameters.Token = Token;
                parameters.TokenSecret = TokenSecret;
                parameters.Nonce = Nonce;
                parameters.Verifier = Verifier;
 
 
                
                requestFactory = new GOAuthRequestFactory("c1", 
ApplicationName, parameters);
                service = new ContactsService(ApplicationName);
                service.RequestFactory = requestFactory;
                feedQuery = new 
ContactsQuery(ContactsQuery.CreateContactsUri("default")); 

                feed = service.Query(feedQuery);


This works fine I get contacts back. However


What I cannot see is how to get photographs of the contacts


The following code comes from some documentation within Google


public static void DownloadPhoto(ContactsRequest cr, Uri contactURL)
{
  Contact contact = cr.Retrieve<Contact>(contactURL);

  Stream photoStream = cr.GetPhoto(contact);
  FileStream outStream = File.OpenWrite("test.jpg");
  byte[] buffer = new byte[photoStream.length];

  photoStream.Read(buffer, 0, photoStream.length);
  outStream.Write(buffer, 0, photoStream.length);
  photoStream.Close();
  outStream.Close();
}

What I cannot see is how these two bits of code can be combined or what is 
the equivelent of GetPhoto from say the Contacts class or the ContactsQuery.


The above code comes from a project where the user logs onto Google, gives the 
application permission to access there account and the app gets a Token back 
which is then converted into a permenant token.


(I have attached the class which retrieves the google contacts)


-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html
?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Contacts;
using CloudClasses.ContactClasses;
using SocialNetworks.Exceptions;
using Google.GData.Client;
using Common;

namespace SocialNetworks.Google
{

    public class Contacts
    {

        /// <summary>
        /// Consumer Key from Google
        /// </summary>
        public String ConsumerKey { get; set; }

        /// <summary>
        /// Consumer Secret from Google
        /// </summary>
        public String ConsumerSecret { get; set; }

        /// <summary>
        /// Scope 
        /// </summary>
        public String Scope { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public String OAuthCallback { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public String SignatureMethod { get; set; }


        /// <summary>
        /// Token from Google Authorisation
        /// </summary>
        public String Token { get; set; }

        /// <summary>
        /// Token Secret from Google Authorisation
        /// </summary>
        public String TokenSecret { get; set; }

        /// <summary>
        /// Nonce from Google authorisation
        /// </summary>
        public String Nonce { get; set; }

        /// <summary>
        /// Verifier from Google
        /// </summary>
        public String Verifier { get; set; }


        /// <summary>
        /// Application Name 
        /// </summary>
        public String ApplicationName { get; set; }

        /// <summary>
        /// UserToken
        /// </summary>
        public String UserToken { get; set; }

        public List<Person> GetContacts()
        {
            OAuthParameters parameters = null;
            GOAuthRequestFactory requestFactory = null;
            ContactsService service = null;
            ContactsQuery feedQuery = null;
            ContactsFeed feed = null;
            List<Person> contacts = null;

            try
            {
                if (ConsumerKey == String.Empty) throw new ValueIsEmptyOrNullException("ConsumerKey");
                if (ConsumerSecret == String.Empty) throw new ValueIsEmptyOrNullException("ConsumerSecret");
                if (OAuthCallback == String.Empty) throw new ValueIsEmptyOrNullException("OAuthCallback");
                if (SignatureMethod == String.Empty) throw new ValueIsEmptyOrNullException("SignatureMethod");
                if (ApplicationName == String.Empty) throw new ValueIsEmptyOrNullException("ApplicationName");
                if (Token == String.Empty) throw new ValueIsEmptyOrNullException("Token");
                if (Nonce == String.Empty) throw new ValueIsEmptyOrNullException("Nonce");
                if (Verifier == String.Empty) throw new ValueIsEmptyOrNullException("Verifier");

                if (Scope == String.Empty)
                    Scope = "https://www.google.com/m8/feeds";;

                parameters = new OAuthParameters();
                parameters.ConsumerKey = ConsumerKey;
                parameters.ConsumerSecret = ConsumerSecret;
                parameters.Scope = Scope;
                parameters.Callback = OAuthCallback;
                parameters.SignatureMethod = SignatureMethod;
                parameters.Timestamp = Toolbox.GenerateTimeStamp();
                parameters.Token = Token;
                parameters.TokenSecret = TokenSecret;
                parameters.Nonce = Nonce;
                parameters.Verifier = Verifier;

                requestFactory = new GOAuthRequestFactory("c1", ApplicationName, parameters);
                service = new ContactsService(ApplicationName);
                service.RequestFactory = requestFactory;
                feedQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));

                feed = service.Query(feedQuery);

                if (feed.Entries.Count > 0)
                {
                    contacts = new List<Person>();

                    foreach (ContactEntry contact in feed.Entries)
                    {
                        try
                        {
                            if (contact.Name != null)
                            {
                                Person person = new Person();

                                int idStart = contact.Id.Uri.ToString().LastIndexOf('/');

                                if (idStart > 0)
                                {
                                    person.PersonId = contact.Id.Uri.ToString().Substring(contact.Id.Uri.ToString().LastIndexOf('/') + 1);
                                }
                                else 
                                {                                
                                    person.PersonId = contact.Id.Uri.ToString();
                                }

                                person.GivenName = contact.Name.GivenName;
                                person.Surname = contact.Name.FamilyName;
                                person.Birthday = contact.Birthday;
                                person.Initials = contact.Initials;
                                person.Location = contact.Location;
                                person.MaidenName = contact.MaidenName;
                                person.Occupation = contact.Occupation;
                                person.Photograph = contact.PhotoUri.ToString();
                                person.Surname = contact.Name.FamilyName;

                                if (contact.Emails.Count > 0)
                                    person.Email = contact.Emails[0].Address;

                                contacts.Add(person);
                            }
                        }
                        catch (System.Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {

                        }
                    }
                }

            }
            catch (Exception ex)
            {                
                throw ex;
            }

            return contacts;
        }
    }
}

Reply via email to