GUS CLASS: Hello, Google Developers, and welcome to
this week's episode of "Google+ Developers Live."
Today we're going to be talking about targeted sharing
on Android.
I'm Gus Class, a Developer Programs Engineer for Google+.
And with me here is Chirag Shah.
CHIRAG SHAH: I'm Chirag Shah, and I'm a Software Engineer on
the Google+ Android SDK.
GUS CLASS: So, great.
So today we're going to be talking again about
configuring and targeting interactive posts on Android.
We'll also talk about how you can think about targeting
these posts on Android.
So as I go through the code, Chirag here, our Android
expert, will be giving us some pointers on what's going on
behind the scenes and some more information on
development with Android for Google+.
So before we begin, Chirag.
Do you want to tell us a little bit more about
interactive posts?
CHIRAG SHAH: So, interactive posts brings users directly to
your Apple website with a call-to-action button.
Clicking the call-to-action button will bring recipients
to a specific place in your app where they
can perform an action.
GUS CLASS: Awesome.
So before we get into the code, let's start with
configuring the application from the developer console.
So, on my screen you can see the Google API's console open.
And what I'm going to do is I'm going to
create a new project.
And then I'm going to give this a meaningful name.
And just so that you know, this is also documented on
developers.googl e.com/plus/quickstart/android.
And so if you want to get started on there, it's an easy
way to quickly get going with developing on Android.
So all the steps that I'm seeing here are also
documented on the web if you want to follow along.
So after I have turned on the Google+ service, then I'm
going to enable API access by creating an
OAuth 2.0 client ID.
And again, you'll just have to put in a meaningful
product name here.
And then after you've done that, you're going to set up
an Android application.
So this is going to be an installed application.
It's going to be installed on the Android devices.
And so I'm going to click Installed Application and then
click Android.
And there's two parameters that I'm going to
have to fill out here.
The first is going to be the package name, and so you just
put in the app name here that you'll get from
your Android project.
And then the second is going to be the signing certificate
fingerprint.
And creating this fingerprint, you're going to use the key
tool which is a thing that allows you to extract
information about your developer certificate.
Chirag, do you want to talk a little bit more about this
signing certificate?
CHIRAG SHAH: Yeah.
So what we're doing here is identifying our Android
Project with Google, and allowing our Android Project
to talk to these various services.
What we're doing here is extracting the SHA1 hash of
the signing certificate for the debug certificate.
And that allows us to keep developing before we go to
production.
Once we go to production, we'll get a different
production key store and extract the
certificate from there.
And generate the SHA1 hash from there and register it
again with Google before going to production.
GUS CLASS: Awesome.
So if we look at my screen again, you can see that I've
loaded up my console and I've got the command for exporting
this certificate.
And so what you would do is after you run that command,
then you copy in this SHA1 hash, paste it into your
console, and then your project is pretty much
set up at this point.
We're going to do one more thing before continuing, and
that is we're going to enable deep linking.
So when I click this reveal button and then turn on deep
linking, it'll let me use deep links from
within my Android app.
Chirag, can you give a little bit more information on deep
linking and Android apps?
CHIRAG SHAH: Yeah.
So deep links allow users to share the exact state of an
application on Google+.
When the pulse is viewed on a mobile device, the user will
be directed to the exact state that was shared on Google+.
If the user doesn't have the app installed, they'll be
prompted to install it on their mobile device.
Ready to start diving into code, Gus?
GUS CLASS: Yeah.
Just one second, I'm going to set up the project.
And so if you look at my screen, you'll see that I have
set up an Android project that has all been configured within
the API's console and is ready to go.
And this is also the exact same project that ships in the
Android SDK, so all this code is pretty much already
available to you.
And what I've done is I've added some functionality to
this sample app that we'll talk about in just a minute,
but let's first look at the plus share code.
So this is inside of the share activity.
And within that share activity is an intent that is returned
and used to render that Share dialog.
And in order to set this up, the first thing that we do is
that we use the PlusShare Builder to construct a
PlusShare object.
And then we configure parameters
from within that builder.
Chirag, can you give us some more information about these
parameters as we look through the code?
CHIRAG SHAH: Yeah.
So we use the PlusShare Builder to create an intent to
the Google+ app to display the Share dialog.
This builder helps us configure the Share dialog to
display exactly what we want.
We use the Add call-to-action button to configure the red
call-to-action button in the Share dialog.
So here in the sample, we're configuring the Share dialog
to display the view item call-to-action.
We also configure what happens once that button is clicked.
So we pass in a call-to-action URL and a call-to-action
deep-link ID.
The call-to-action URL is used on desktops and the deep-link
ID is consumed on mobile devices.
Next, we set the content URL.
The content URL helps us define what data gives context
to the user about which action they're going to perform.
So in this case we're setting the content URL to our
developer documentation.
And from there we've annotated it with Schema.org markup,
which displays what description should show up in
the Share dialog and also what type of image should augment
and give more context to the user.
GUS CLASS: So there's two sets of links that we're really
talking about here.
So I'll get this started so we can see what's going on, but
there's two sets of links here.
The first set is the content links, and then the second set
is going to be the call-to-action links.
So want to differentiate between these
a little bit, Chirag?
CHIRAG SHAH: So the content URL is used around the
call-to-action, so it's placed on top of it as you can see in
the Share dialog.
And once you click on it, it points users to the particular
research that's being shared.
Whereas for the call-to-action URLs, it basically guides the
user to perform a particular action in that application.
And the deep-link IDs are used for mobile clients to navigate
users to a particular use resource that's being shared.
GUS CLASS: So if we look at my screen again, we can see the
sample running on my phone.
So this is the same sample that you know and love.
It ships with the SDK.
And this is as it would run just as if you hadn't made any
changes yet.
So when I create the interactive post and I click
Go, what you'll see is you'll see the same thing that you
see on my screen.
You'll see the pre-filled text that is from this
line of code here.
You'll see the content URL which is going to be rendered
on this part of the screen near the bottom.
And then you will see this View Item
call-to-action button.
So if I'm correct, the call-to-action links will
determine which content appears inside of this button.
And then the content is what appears inside of that little
rendered area on the bottom of the screen.
CHIRAG SHAH: Exactly.
So the content URL gives a little more information to the
user about what's being shared and what type of action they
would be performing once they click on the
call-to-action button.
GUS CLASS: Awesome.
Thanks, Chirag.
So I'm going to go look at one more thing.
So if I click on who this post is being shared with, the
little dialog box that appears in the top of the post, I'll
notice that it's set to public.
Now, where did that public come from, Chirag?
CHIRAG SHAH: That's a good question.
So that's actually the last Share target specified in the
Google+ Share dialog.
So last time we shared on Google+ and
filled out some people.
It'll get displayed again, but we can do a little better with
interactive posts.
We can actually set a specific set of people in the Share
dialog and actually get targeted sharing.
So with the PlusShare Builder, you can specify the method Set
Recipients, and from there you can set the exact Share target
that your application wants.
GUS CLASS: Awesome.
So let's return to the code here, and here is that
setRecipients method.
And what I'm going to do later on in the code is I'm going to
create an array list of recipients that I'm then going
to use for the Builder method for setRecipients.
So I've cheated a little bit here, and I've already written
a lot of the code.
But let's walk through the important sets of the code so
that you can understand what's going on here.
So when I turn on that Best flag, what's going to happen
is, instead of just starting the activity, what I'm going
to do is I'm going to call this method loadPeople.
And what that is is this is an implementation of an interface
that's specified by the Google+ platform.
And so if you look at the very top of my code, you can see
where I have copied and pasted this onPeopleLoadedListener
from the listPeople activity.
And what that will do is when that method is called, this
callback function for onPeopleLoaded will be called,
and then inside of here will be data.
Chirag, can you give some more information on how these
pieces connect?
CHIRAG SHAH: Yeah.
So when you call Plus Client and loadPeople, it's actually
an asynchronous call.
And Google Play Services will go out to the network, fetch
the specific set of people as determined by the network, and
return that back to your application as specified by
your Callback interface.
So once the people have been loaded, it'll specify a
passive person buffer into the onPeopleLoaded handler.
And Person Buffer is actually a cursor-like interface, and
once you're done loading the specific people from the
buffer, you'll have to close it as to
avoid any memory leaks.
GUS CLASS: OK, so we have this person buffer, and then we can
take those objects and then we can add them to this array
list of best recipients.
And then later, before we retrieve this intent and then
we start the activity for results, what will happen is
we'll have that list of people already added into the data
that's set up by the Share dialog.
So while this loads, do you want to talk a little bit
about why you want to call startActivityForResult?
CHIRAG SHAH: So when you call startActivityForResult, it
gives attribution to your calling package and helps
render the Share dialog with attribution.
And you'll need to do this for interactive
posts or it won't work.
GUS CLASS: OK, so there you go.
Make sure that you call
startActivityForResult so that it works.
So let's run the same code that we ran before now that we
set the recipients for this post.
So if everything worked correctly, what we'll see is
we'll see the list of the best recipients.
This is something that's worth mentioning.
When I performed that method loadPeople, on the backside
it's doing a list of the people using the Google+
Platform API.
And this allows you to sort by alphabet, or it allows you to
sort by best.
And so I've done a sort by best, and so the top five best
people that are associated with my demo account here will
be returned to my app.
So if we look at the list here, here's the five people
and this looks good.
Chirag's missing.
I don't know why, because he's one of my best people.
But there's also something else that's different.
You'll notice that that list of recipients that we had set
before, Public is no longer there.
Chirag, why is this happening?
CHIRAG SHAH: So back when we called the setRecipients
method in the PlusShare Builder, we set the specific
share target for this Share dialog, and that actually
overrode the previous Share target because our application
is specifying exactly who should be shared with.
GUS CLASS: OK, so that's it for today.
You've seen us taking an interactive post and then
adding specific recipients to it so that you can create a
much more contextually useful and relevant
post for your users.
And next, what we've done is we've set up that post and
then rendered it to the stream.
And then when you set that list of recipients, then
you're ready to go.
So it looks like we may have some questions?
MALE SPEAKER: We do have a couple questions, thanks, Gus.
So one question is from Gerwin.
He wants to know if there's a way to have a deep-link ID but
still allow people to access the content URL if they don't
want to install the app for some reason.
So the question is, is there a way to have a deep-link ID but
still allow people to access the content URL if they don't
want to install the app for some reason?
GUS CLASS: OK, so you have a deep-link ID, but you--
CHIRAG SHAH: So that won't work right now, but that is
really good feedback, and that's something I'll take
back to the appropriate teams.
MALE SPEAKER: So another question, Gus.
I was a little concerned you showed your best people and
you didn't have your friendly GDL producer
listed in that top five.
How does Google+ determine that affinity of who gets in
that top five?
And what do I need to do to get in that top five?
GUS CLASS: So I don't have this
specific information here.
It is calculated by Google based on the available
information that Google has and the interactions that you
have on Google+.
So be a very friendly person and do all the great things
that would make you a close friend of mine, and then you
would appear in my best friends list.
MALE SPEAKER: Over on YouTube, there was another question.
Chirag, how does somebody get such an
awesome shirt as yours?
They want to get this Google API shirt.
And do you have multiple, and can you give
some of those away?
CHIRAG SHAH: This is actually a limited edition, and we no
longer make these type of shirts.
MALE SPEAKER: Was the shirt deprecated?
CHIRAG SHAH: Yes.
GUS CLASS: That's a deprecated shirt.
So I believe Google may also have a store where you can get
some of the Google-branded stuff.
I don't know specifically where that is, though.
CHIRAG SHAH: Yeah.
MALE SPEAKER: Googlestore.com.
GUS CLASS: Googlestore.com, all right.
Any final questions?
All right, so that's it.
Everything that we've shown today is well documented on
the Google+ Platform Developers page,
developers.google.com/plus.
The sample that we showed for Android is available from the
SDK, and so if you go to the documentation page that I
showed you earlier, you can find the sample.
CHIRAG SHAH: And you can also find all of our samples on
github.com/googleplus, where you can find samples and all
of our supported languages, and they also demonstrate the
best practices for integrating with Google+.
I find this to be the best resource when trying to learn
a new language, such as Go or C# because it shows how to
integrate with Google+, but it also shows how to use that
language and make typical rest calls.
GUS CLASS: It's really great to hear that feedback, Chirag,
because when we created the samples, we tried to create
them as consistent as possible so that if you're switching
from one language that you're comfortable in and moving to
another one that you're less comfortable in, you can
understand what's going on inside of the sample.
It's worth mentioning that we also have
additional support materials.
If you go to developers.google.com/plus and
then go on the left nav, you can find additional
information about our support communities such as Stack
Overflow, where we use the tag Google-Plus.
And also the community page on Google+, where a lot of
developers are engaging with each other all the time.
So that's it for today.
Chirag, thank you so much for coming in.
It's great to have an Android expert on here.
CHIRAG SHAH: Thank you for having me on, Gus.
GUS CLASS: All right, so until next week, stay around and be
sure to watch as we have future episodes of "Google+
Developers Live."