Created
May 26, 2016 11:14
-
-
Save LindaLawton/313bf498dddb5cf96380bdc38809ec35 to your computer and use it in GitHub Desktop.
How to merge the Google APIs Client library with the Gdata client library to access Google Contacts using C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Google.Apis.Auth.OAuth2; | |
using Google.Apis.Util.Store; | |
using Google.GData.Client; | |
using Google.GData.Contacts; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace GoogleContactsTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Install-Package Google.GData.Contacts | |
// Install-Package Google.Apis.Auth | |
var clientId = "XXX.apps.googleusercontent.com"; | |
var clientSecret = "XXX"; | |
string[] scopes = new string[] { "https://www.google.com/m8/feeds/" }; | |
// Requesting Authentication or loading previously stored authentication for userName | |
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } | |
, scopes | |
, "xya" | |
, CancellationToken.None | |
, new FileDataStore("Google Contacts V3")).Result; | |
var m = credential.GetAccessTokenForRequestAsync(); | |
var requestFactory = new GDataRequestFactory(null); | |
requestFactory.CustomHeaders.Add("Authorization: Bearer " + credential.Token.AccessToken); | |
var service = new ContactsService("App Name") { RequestFactory = requestFactory }; | |
FeedQuery feed = new FeedQuery(); | |
string feedUrl = "https://www.google.com/m8/feeds/contacts/default/full"; | |
// Instantiate a SpreadsheetQuery object to retrieve spreadsheets. | |
ContactsQuery myQuery = new ContactsQuery(feedUrl); | |
ContactsFeed resultFeed = service.Query(myQuery); | |
foreach (var contact in resultFeed.Entries) { | |
var l = contact.Title; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment