Google People API / Other Contacts - how to get photos of other contacts? - google-api

Google forces us to migrate from the deprecated Contacts API over new People API.
They even implemented "Other Contacts" feature in the People API which was so demanded.
But now I'm facing another problem - there is no way to get photos of Other Contacts in the People API.
I was digging into this problem and figured out that it's possible to add photos into the readMask (even though it's not documented):
https://people.googleapis.com/v1/otherContacts?access_token=<...>&readMask=emailAddresses,names,photos
...but it doesn't help, because it returns the default picture with the first letter for all contacts, even for contacts who has a real photo. Like this one: https://lh3.googleusercontent.com/cm/ABXenNkcRSTRZU8PEFQfJtaeEBZnxLgN-UO555npUt1idzcMohoSGuJFfKx0JX2AR6Qp=s100
I tried to add coverPhotos into the readMask but it doesn't let it there.
Then I was checking how old Contacts API formats photo urls and figured out the format:
https://www.google.com/m8/feeds/photos/media/<user-email-address>/<contact-id>
But it has 2 disadvantages:
this url has to be requested with access_token
it works only if the contact uploaded a custom photo, otherwise it returns error
So here is my question:
Is there any simpler and cleaner way to get real photos of Other Contacts in People API?

This bug has been solved and now we have a solution!
Updated documentation: https://developers.google.com/people/api/rest/v1/otherContacts/list
There is a new sources[] request parameter. To get the real photos of "other contacts" you need to specify 2 values: READ_SOURCE_TYPE_CONTACT and READ_SOURCE_TYPE_PROFILE.
The request would look like this:
GET https://people.googleapis.com/v1/otherContacts?readMask=photos&key=API_KEY&sources=READ_SOURCE_TYPE_CONTACT&sources=READ_SOURCE_TYPE_PROFILE
Now some contacts will contain 2 entries in the photos array:
photos: [
{
metadata: {
primary: true,
source: {
type: "PROFILE",
id: "11111"
}
},
url: "<THIS IS THE REAL PROFILE PICTURE>"
},
{
metadata: {
source: {
type: "OTHER_CONTACT",
id: "6666666"
}
},
url: "<THIS IS THE DEFAULT PHOTO STUB>",
default: true
}
]

The readMask fields accepted for the otherContacts.list method are the following:
emailAddresses
metadata
names
phoneNumbers
photos
As you can notice, the photos field is an accepted one while making the above request.
However, the returned response should yield a url which redirects you to the user's profile picture. Because of this, I have taken the opportunity to report it on Google's Issue Tracker here. I suggest you star the issue as any updates regarding this will be posted there.
Reference
People API otherContacts.list;
People API Support.

Related

Change label in Google contacts

I want to synchronize contacts in my application with Google contacts. But not all of them, just those with the right label (tag). I'm using Google's People Apis for this. But I ran into a problem, the memberships property/field which holds informations about labels is read only. I can't even create a contact/person with the right label. It throws an error. Is there a way how to update or create a contact with label?
For mor information head here.
EDIT:
I've tried both creating and updating a contact. Sending a POST and PATCH request message on https://people.googleapis.com/v1/people:createContact (similiar to update contact). Both fail with the same error, memberships parameter is read-only.
contactGroupId is the id of the label I'm trying to assaign to the contact.
Request body:
{
"memberships": [
{
"contactGroupMembership": {
"contactGroupId": "45asd3d7321gd"
}
}
]
... //Other parameters
}
You should use contactGroups.members.modify api call

Google Places API for Hospitals

I am using Google Places API to search nearby hospitals from a location. My problem is that I want to get famous and big hospitals but the problem is the API is fetching clinics and even dental clinics too. How I can be more specific?
Query URL : https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=24.9044526,67.077706&type=hospital&radius=500&key=[API_KEY]
Although they are not famous even the medical facilities provided there are not sufficient for emergency case.
I have also tried increasing the radius but got same response.
I know this post is a bit old but this worked for me:
var request = {
location: location,
rankBy: google.maps.places.RankBy.DISTANCE,
type: "hospital",
keyword: "(emergency) AND ((medical centre) OR hospital) AND (24 hours)",
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);

How to create interest in interest category?

As per below link create interest functionality is nto avaialable.
http://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/interests/#
But using API playgroung you can create interest. Even tried with REST api and I am able to create interest. Please let me know if "create interest " API has been removed from above page.
I think it never wasn't on that page. This new API Documentation lacks many things that are possible.
If you want to create new interest you can just POST to this endpoint:
/lists/{list_id}/interest-categories/{interest_category_id}/interests
Example request body:
{
"list_id": "id_of_the_list",
"name": "name of the interest",
"display_order": 1
}
So the answer for your question is that I am pretty sure they just haven't created documentation for that one yet.

Parse.com Stripe: Creating a charge that is not captured

I'm working on an iOS app that uses Stripe to process payments. We are moving from a system that uses two separate charges for initial purchase and tip to a system that uses a single charge that begins as a hold on the user's account and then is captured upon setting the tip. This was the system that Stripe recommended to us when we inquired how to work with a single charge but also validate that the card can handle a charge of the designated amount.
For our back end, we are using Parse.com to track our orders, and so we are using Stripe's integration with Parse.com's Cloud Code as our server. Our main issue is that Parse.com doesn't seem to outright support most of Stripe's functionality (i.e. capturing charges). After some searching, I found that http POST requests were the best option to interact with Stripe.js and actually capture charges. However, I haven't been able to get quite that far because Parse.com is giving me a Code 141 error (Received unknown parameter: captured) when I try to create a charge that is uncaptured. Parse.com's Stripe API suggests that you can set all parameters through their Stripe.Charges.create, but it won't accept captured as a valid parameter.
To abstract for anyone else with this issue, how can I create a charge that has the parameter captured set to false using Parse.com Stripe API?
I have posted some of my Cloud Code below that should define a method to create a charge that has not yet been captured. This method is what is giving me the error that captured is not a valid parameter.
/**
* Create Hold on Card
* Required:
* orderCostInCents -- in cents ex. $10.24 = 1024
* customer -- cus_11EXEXEXEXEXEX
* description -- order.objectId to link it with order item.
*/
Parse.Cloud.define("holdAccount", function(request, response) {
//response.success("Not Charged");
var Stripe = require("stripe");
Stripe.initialize(kStripePrivateKey);
Stripe.Charges.create({
amount : request.params.orderCostInCents,
currency : "usd",
customer : request.params.customer,
captured : false,
description : request.params.description
},{
success: function(httpResponse) {
console.log(httpResponse);
response.success(httpResponse);
},
error: function(httpResponse) {
console.log(httpResponse.message);
response.error("Failed to create charge");
}
});
});
I believe that I can structure an http (POST) request after creating the charge by following the guidelines set at https://www.parse.com/questions/stripe-payment-capture-method-not-available. This guide might be very helpful to anyone else with my issue!
Best, and thanks for your help!
Edit: I realized that I didn't post the version of Cloud Code that we are using. It is 1.2.19.
Well, after taking a break from my hours of staring at the screen, I certainly feel like a doofus! The parameter I was using was captured, where the correct parameter should be capture. I was able to fix my issue by simply removing the "d" from the parameter name while creating the charge.
Whoops! I would still be open to advice on http requests via comments, but I will test those on my own and post a separate thread if I run into issues there as that issue is tangential to this one and thus off-topic.
For everyone joining, the answer is that the above code works perfectly if you replace the parameter captured with capture
Edit: For anyone else that is interested, the follow-up to this question was about actually making the capture via http requests on Parse Cloud Code. The following method works after much searching and trial and error. The hardest part here was figuring out how to format the URL since this is my first foray into http requests. If you need to chain parameters, simply add "&{parameter-name}={parameter-value}"
//kStripePrivateKey is your stripe private key
//Must pass in chargeID = stripe charge id and
//orderCostInCents = capture amount in cents as parameters
var captureURL = "https://"+ kStripePrivateKey +
":#api.stripe.com/v1/charges/"+
request.params.chargeID+
"/capture?amount="+request.params.orderCostInCents;
Parse.Cloud.httpRequest({
url: captureURL,
method: 'POST',
success: function(httpResponse) {
// Handle any success actions here
response.success(httpResponse);
}, error: function(httpResponse) {
response.error(httpResponse);
}
});

Google API for Restaurants Places

I am having problems understanding the Google Places API. I am building an iPhone application with a nearby feature that allows the user to find restaurants located around the user's GPS. How can I obtain a Google API for this? Do I have to have one custom made how does this work? If I also wanted to create an API for points of interest how can I do that?
There is a Google Places API for searching for nearby locations. The documentation is here: https://developers.google.com/places/documentation/search#PlaceSearchRequests
But I'm guessing you already found that. If you ask more specific questions, we can be more helpful.
You can use Google place API , and if you want to display only specific type of places e.g restaurant in your cases you can use request object as shown in the code below
var request = {
location: pyrmont,
type: ['restaurant']
};
infowindow = new google.maps.InfoWindow();
places = new google.maps.places.PlacesService(map);
places.nearbySearch(request, callback);
For more details on type filteration in google place API you can check the Link on Google Developers.
But nearby search taking only one type parameter, and it is only restaurants. Not food, not cafe, only restaurants, which Google API provides, if you are looking for the public catering establishments.
First of all, the Google Paces API should be active.
function displayRestaurantAround() {
return new Promise((resolve, reject) => {
this.service.nearbySearch({
location: currentUserPosition,
radius: 5000,
types: ['restaurant']
}, (res) => {
resolve(res);
});
});
}

Resources