Hello, internets, and welcome to this week's episode of
Google+ Developers Live.
So we're going to take a break from the best practices
episodes that we've been doing, and we're going to be
showing you the Quickstarts.
So this week, we'll be doing the C# Quickstart on Windows,
and the short version of what this does is it's going to
create a web server built on top of ASP.NET, and it's going
to host a [INAUDIBLE]
that will render the Sign-In button, sign in the user, and
then pass authorization tokens to the server in order to make
API calls server side.
So if you want to get started with this, the launching off
point is going to be developers.googl
e.com/plus/quickstart/C#.
So let's take a look at my screen and
walk through the sample.
So here you have the landing page for the C# sample, and
inside of this set of instructions is going to be--
the first command is going to be for cloning the actual
sources from our GitHub project page
into your local machine.
So what you would do is just copy this command, get clone,
GitHub.com/Googl e+/G+quickstartC#.get.
So let's run that command.
So what it's doing is it's just copying the sources from
GitHub into my local machine.
So now, in the folder that I've set up for my Git Bash, I
will now have the Google+ Quickstart.
So here's the Quickstart itself.
Now what I will do is, I'm just going to open up the
solution inside of Visual Studio.
So once the solution's opened, what I'm going to have to do
is set up the client credentials before I'm going
to be able to make API calls on behalf of the user.
So what I'm going to have to do next then is set up an API
project inside of the API's console.
The place that you start here is
code.google.com/APIs/console.
Here we have the API's console.
For those of you who are unfamiliar with it, this is
where you create all the projects that use Google APIs.
So if I want to create a project that uses the Google+
APIs, for example, then this is where I would start.
So let's create a new project.
When you create the project, the first thing you need to do
is come up with a name for your project.
So the name that you give your project is just for you.
This is not going to be a public-- this is not going to
be public facing information.
This is just information so that you know one of your
projects from another.
I'll just create a project for this GDL.
Here's the project that's created.
And after the project gets created, you then turn on the
services that your project is going to consume.
So because this project is only going to be using the
Google+ API, I just need to turn on the Google+ API.
So it's right in the middle, and it's sorted alphabetically
for those of you who are hunting through, and the plus
in Google+ actually appears as a P in the
alphabetical ordering.
After you've created your project, and you've turned on
the service for Google+, you now are ready to create your
authorization credentials.
So what I did there was I clicked this Create An OAuth2
client ID button, the big blue one.
And inside of here is going to be the branding information
that will be facing your customers.
So when you label this information, please take the
time to ensure that the information is accurate and is
consistent with the branding for your particular product.
Because this is just a GDL Quickstart, I'm just going to
have a less meaningful name, but this is fine for now.
So I'm going to be creating a web application, and I'm going
to be running it from local host port 4567, just as is set
up inside of the tutorial.
The reason that I switched this also was because HTTP
versus HTTPS matters.
So when you set up these projects, pay extra careful
attention to the port and the protocol that you're using,
because it needs to match wherever you're going to be
running this code.
So I'll create that client ID, and after that's done, what
will happen is there'll be a client ID and a client secret.
And so these are the credentials that Google uses
to ensure that the people who are accessing the APIs are the
right ones for that particular project.
So make sure that you protect this information on your
deployed applications.
Here we have the project again.
I'm going to open signin.ashx, and this will actually open
the code-behind.
And so inside of the code-behind is the settings,
your client ID and your client secret.
So these are the ones that you got from the API console.
So here's the client ID, the client secret, and now, if we
run the sample, you will see the application running.
Here's the sign-in dialogue.
I click it.
I'm presented then with this request for permission.
So all of the services that are set up and included inside
of the scopes will appear here for your users.
So make sure that when you request scopes, you request
the right ones for what your users will be doing.
After you've done this, you accept, because you trust this
product, and then after you accept, the sample will run.
So what happens when the sample runs is, up top we
render some really minimal UI, and then we use the JavaScript
client library in order to retrieve a user profile, and
then we perform a RESTful API call to the server endpoint
which was created.
And then that will retrieve HTML for the people that are
visible to this app.
So there's a server side call that's happening there.
There's a client call that's happening there.
And so once you've got this working, then you've seen the
Google+ Client Libraries running inside of your Google+
application.
And that's pretty much all there is to it for the
Quickstart.
Now, let's take a closer look at some of the things that are
happening behind the scenes when this is done.
I'm going to put a breakpoint in here, and this breakpoint
will cause the code to pause when we have retrieved the
user's list of circled people.
So let's see where the endpoint is for that.
So here's the request path that contains people, and here
you can see something that starts to look like
a Google API call.
So you have this PeopleFeed object, you've got- PS is
actually a plus service object, and then inside of the
plus service object, all of the client APIs are
encapsulated into methods and objects.
So this is a real simple API call.
Doing this does not require very much setup, very much
work, and when you run it, the result that you get is going
to be that object representing the list of people.
I'll just go back to my server again.
We'll run the sample again, and here's where that server
has set up that PeopleFeed request.
And after it's concluded with that fetch command, you'll
have, inside of this PeopleFeed, an object that
just represents something from that users Google account.
This gives you a general idea of how to get started with
Google+ and the Google+ Client Libraries and C#.
And feel free to ask questions on our Google+ Developers page
in the Google+ Developer community on Google+.
And feel free to reach out to us directly on Google+ if
you'd like to as well.
Once you have all this set up, you're pretty much ready for
C# development, but what if you wanted to use or create a
client application.
So this is sort of one of the problems that our client
libraries team has been thinking of, and they recently
announced a new version of the Google API libraries.
And this is built on top of the PCL, and so when you use
the new library, you can put your applications on Windows
Phone, on Windows desktop, and in the new Windows 8.
Feel free to check out that new library, but there are few
quirks to it that I want to share with you
before we move on.
So I'll close the solution, and I'll open up-- so I have
another one.
I have another solution that has been updated to the new
client library.
When you set up these projects, it's basically the
same setup that we had. before.
You just want to add references for DotNetOpenAuth,
the Google APIs library, OAuth2, and then the Google
Apis.Plus.v1.
So if you look inside of my project references, you can
see where I've added these four.
The next thing you need to do is you need to turn on the New
Git packages for all the BCL stuff and also for the
dependencies of the new client library.
So the major dependency is the Microsoft HTTP client
libraries, and so you want to make sure that you include
that, and then that should also pull in the other
components.
You also will need to pull in the [INAUDIBLE] for .NET
framework library and then the Newtonsoft.JSON.
We used to ship the sample with Newtonsoft.JSON in it,
but now that you can acquire these libraries very easily,
get the latest ones using New Git, it just makes sense to
instead ship it without, and then have people who are
playing with the API to just add it themselves.
So that's pretty much it.
Everything looks and works exactly the same.
When I updated to this new client library inside of my
test app, there were absolutely no changes that I
had to make to my code.
Everything just was using the same API footprint.
So there were no major breaking changes except you
just now have to be able to import all these libraries
that are required for Microsoft HTTP.
So that's it for today.
Thank you for watching, and come back next week at the
same time, 2:30 PM PST, to watch another episode of
Google+ Developers Live.