We are integrating social signup with google in our project, so we have to get the phone number from the users google account. we were able to fetch the phone number from people API(by using phoneNumber scope), but its not returning any country code info. please help us to get the country or country code info along with phone number.
The scope we used is: https://www.googleapis.com/auth/user.phonenumbers.read
and we used this API to fetch phoneNumbers:
https://people.googleapis.com/v1/people/me?personFields=phoneNumbers
we got the response as
{
"resourceName": "people/11454441970xxxxxx",
"etag": "%EgUBCy43PxoEAQIFByIMaXF6QTFjxxxx",
"phoneNumbers": [
{
"metadata": {
"primary": true,
"source": {
"type": "DOMAIN_PROFILE",
"id": "11454441970xxxxxx"
}
},
"value": "95xxxxxxxx",
"type": "work",
"formattedType": "Work"
}
]
}
The field you are looking for is called canonicalForm which is the The canonicalized ITU-T E.164 form of the phone number.
The people api is very picky with what information the user has summited. If the user you are looking at did not add the country code then its not going to appear
As you can see with my settings on my google profile I have set my country code with my phone number
.
So when i make a request to the api.
curl \
'https://people.googleapis.com/v1/people/me?personFields=phoneNumbers&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
My phone number is returned in the id field and country code and number in the canonicalForm fields.
"phoneNumbers": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "3fab08baa4be"
}
},
"value": "xxxxxxxxx",
"canonicalForm": "+45xxxxxxxxx",
"type": "mobile",
"formattedType": "Mobile"
},
I would check the data that the user has inserted into their google profile and ensure that they have set the country code.
Related
I'm trying to send an email out using Mandrill by adapting the curl command from https://mailchimp.com/developer/transactional/api/messages/send-new-message/ and using the API key from https://us1.admin.mailchimp.com/account/api/ and I'm getting an error that doesn't make a lot of sense to me. Here's the command I'm running:
curl -X POST \
https://mandrillapp.com/api/1.0/messages/send \
-d '{"key":"...","message":{"html":"hello, world!","subject":"hello, world!","from_email":"neubert#neubert.com","to":["neubert#neubert.com"]}}'
Here's the response:
{"status":"error","code":-2,"name":"ValidationError","message":"Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"}
Here it is decoded:
{
"status": "error",
"code": -2,
"name": "ValidationError",
"message": "Validation error: {\"message\":{\"to\":[\"Please enter an array\"]}}"
}
I don't understand. "to" is an array...
Any ideas?
Thanks!
I also got the same error at first then going through the documentation keenly, I noticed that the to field in message is NOT a list of email addresses. I know it's intuitive that way!!
It's a list of object's with 3 fields: email, name and type.
An ideal JSON Body will be as follows:
{
"key": "<YOUR_MANDRILL_API_KEY>", # Caution! It is not a mailchimp API key
"message": {
"html": "testing html part",
"text": "testing text part",
"subject": "testing subject",
"from_email": "<FROM_EMAIL_ADDRESS>",
"from_name": "<FROM_NAME>",
"to": [
# Recipient 1
{
"email": "<Recipient1_EMAIL_ADDRESS>",
"name": "<Recipient1_NAME>"
},
# Recipient 2
{
"email": "<Recipient2_EMAIL_ADDRESS>",
"name": "<Recipient2_NAME>"
}
]
}
}
I am using
https://www.googleapis.com/calendar/v3/calendars/en.australian%23holiday%40group.v.calendar.google.com/events?key=YourApiKey
to get australian public holidays, but I am receiving empty items array
{
"kind": "calendar#events",
"etag": "\"p32kslj59m6eeu0g\"",
"summary": "Holidays in Australia",
"updated": "2021-03-05T08:30:05.375Z",
"timeZone": "UTC",
"accessRole": "reader",
"defaultReminders": [],
"nextPageToken": "CjASLgojMjAyMTA0MDVfNjBvMzBjaGk2b28zMGMxZzYwbzMwZHI1NmsYkN324_Pw7gIaDwgAEgAYmKz8oN6Y7wIgASIHCAIQzunfEQ==",
"items": []
}
any idea how to get australian holidays?
Google Calendar API is returning the correct results, but it is returning them across several pages. You can get the next page with:
https://www.googleapis.com/calendar/v3/calendars/en.australian%23holiday%40group.v.calendar.google.com/events?key=YourApiKey&pageToken=CjASLgojMjAyMTA0MDVfNjBvMzBjaGk2b28zMGMxZzYwbzMwZHI1NmsYkN324_Pw7gIaDwgAEgAYmKz8oN6Y7wIgASIHCAIQzunfEQ==
See more about pagination here: https://developers.google.com/calendar/v3/pagination
The client libraries make it easy to deal with these multi-paged responses.
The page size defaults to 250 events, but this also includes deleted events, which you are not requesting. The first 250 events on this particular calendar have been marked as deleted, so you see an empty page.
See details at: https://developers.google.com/calendar/v3/reference/events/list
maxResults (integer)
Maximum number of events returned on one result page. The number of events in the resulting page may be less than this value, or none at all, even if there are more events matching the query. Incomplete pages can be detected by a non-empty nextPageToken field in the response. By default the value is 250 events. The page size can never be larger than 2500 events. Optional.
I was able to force everything onto a single page using the following, but this really isn't a good answer. If total event count is larger than 2500, you still might end up with an incomplete list:
https://www.googleapis.com/calendar/v3/calendars/en.australian%23holiday%40group.v.calendar.google.com/events?maxResults=2500&key=[YOUR_API_KEY]'
There seems to be an error in that the initial response returns no events however there is a page token This is not how the system is intended to function. I have submitted an issue report
try me
Request;
curl \
'https://www.googleapis.com/calendar/v3/calendars/en.australian%23holiday%40group.v.calendar.google.com/events?key=[YOUR_API_KEY]' \
--header 'Accept: application/json' \
--compressed
Returns
{
"kind": "calendar#events",
"etag": "\"p33kpjmcjvaeuu0g\"",
"summary": "Holidays in Australia",
"updated": "2021-03-06T07:14:02.000Z",
"timeZone": "UTC",
"accessRole": "reader",
"defaultReminders": [],
"nextPageToken": "CjASLgojMjAyMTA0MDVfNjBvMzBjaGk2b28zMGMxZzYwbzMwZHI1NmsYkN324_Pw7gIaDwgAEgAYgMXbj4-b7wIgASIHCAIQ5I7jEQ==",
"items": []
}
Where it should return events
If i then add the next pagetoken
Request
curl 'https://www.googleapis.com/calendar/v3/calendars/en.australian%23holiday%40group.v.calendar.google.com/events?pageToken=CjASLgojMjAyMTA0MDVfNjBvMzBjaGk2b28zMGMxZzYwbzMwZHI1NmsYkN324_Pw7gIaDwgAEgAYgMXbj4-b7wIgASIHCAIQ5I7jEQ%3D%3D&key=[YOUR_API_KEY]'
--header 'Accept: application/json'
--compressed
response
{
"kind": "calendar#events",
"etag": "\"p32e9tk5uvaeuu0g\"",
"summary": "Holidays in Australia",
"updated": "2021-03-06T07:14:02.000Z",
"timeZone": "UTC",
"accessRole": "reader",
"defaultReminders": [],
"nextPageToken": "CjASLgojMjAyMjEyMjZfNjBvMzBjaGk2NG8zNGMxZzYwbzMwZHI1Nm8YsM-liJbz7gIaDwgAEgAYgMXbj4-b7wIgASIHCAIQvo_jEQ==",
"items": [
{
"kind": "calendar#event",
"etag": "\"3227284619238000\"",
"id": "20200425_60o30chi6so3gc1g60o30dr56g",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=MjAyMDA0MjVfNjBvMzBjaGk2c28zZ2MxZzYwbzMwZHI1NmcgZW4uYXVzdHJhbGlhbiNob2xpZGF5QHY",
"created": "2021-02-18T09:58:29.000Z",
"updated": "2021-02-18T09:58:29.619Z",
"summary": "ANZAC Day Observed (Victoria)",
"description": "Holiday or observance in: Victoria",
The response is returned corectly.
I have created the google project and using the youtube data api v3 key in below url but not getting channel statistics.
https://www.googleapis.com/youtube/v3/channels?parts=statistics&id=UCQ_jR_iUmDsR50GX33qWvog&key=AIzaSyBDEjJeaI2QEzNuFNrjPAsFHl1Jin9JWsw
Output is below
"kind": "youtube#channelListResponse",
"etag": "5PVGuDob8dxpfgpaJGWruEW8hV8",
"pageInfo": {
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "Z0A5YSAnQtcEnTTvtERboPwQAk0",
"id": "UCQ_jR_iUmDsR50GX33qWvog"
}
]
}
Assuming you are working with channel.list I think you should check your code I just tested this with your same request and it works fine from here. tryme
Request:
curl \
'https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UCQ_jR_iUmDsR50GX33qWvog&key=[YOUR_API_KEY]' \
--header 'Accept: application/json' \
--compressed
Response
{
"kind": "youtube#channelListResponse",
"etag": "1a3o4gpa3kaJyNIWXi2yvRgmk4s",
"pageInfo": {
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "S7lD_zHbbGaTaOHU3iEyjECpr0c",
"id": "UCQ_jR_iUmDsR50GX33qWvog",
"statistics": {
"viewCount": "488",
"commentCount": "0",
"subscriberCount": "2",
"hiddenSubscriberCount": false,
"videoCount": "13"
}
}
]
}
anwsers from comment questions
How your project is able to access my youtube channel?
You are using an API key that grants access to public data. Which is what i am doing as well. Stats on your channel is public data.
Like you testing it on browser it is working but I copy the same python code to my local machine and try to run it is promoting for key.
You didn't post your code i cant help you with that. What you have shown shows a hard coded public key= paramater.
how to bypass or get rid of prompt?
I am using a public api key there is no prompt as its requesting public data.
I'm creating a bot using REST API. Indeed, I want to send a message from my bot to me as following
I start with 'Authentification'
Request:
curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id={app_id}&client_secret={app_password}&scope=https://graph.microsoft.com/.default"
Response:
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "<access_token>"
}
Next, I start a new conversation
Request:
POST https://skype.botframework.com/v3/conversations
Authorization: Bearer <access_token>
Content-Type: application/json
{
"bot": {
"id": "standupalice",
"name": "Standup Alice"
},
"isGroup": false,
"members": [
{
"id": "<my bot id>",
"name": "Standup Alice"
},
{
"id": "<my user id>",
"name": "Bao"
}
],
"topicName": "News Alert"
}
NOTE: and are obtained from a callback message sent from Skype app to Standup Alice bot.
Response:
{
"id": "<conversation id>"
}
It's weird since the conversation ID is identical to . Well, now I compose a message to send to me as following
Request:
POST https://skype.botframework.com/v3/conversations/<conversation id>/activities
Authorization: Bearer <access_token>
Content-Type: application/json
{
"type": "message",
"from": {
"id": "<my bot id>",
"name": "Standup Alice"
},
"conversation": {
"id": "<conversation id>",
"name": "News Alert"
},
"recipient": {
"id": "<my user id>",
"name": "Bao"
},
"channelId": "skype",
"text": "My bot's reply"
}
Response (http error 400 - bad request):
{
"error": {
"code": "ServiceError",
"message": "The conversationId <conversation id>and bot <my bot id> doesn't match a known conversation"
}
}
Do you have an idea what's wrong with my requests and parameters?
Note 1: I tried to fire request to https://api.botframework.com/v3/conversations as described in https://docs.botframework.com/en-us/core-concepts/overview/#navtitle, but always receives http error 404 - Resource not found.
Note 2: I just tried the same way for webchat and it works fine, but MS Teams doesn't work (http error 500 - Internal Server Error)
Note 3: my channel settings
Your second API request (the one starting a conversation) should have returned something looking like this:
{
"activityId": "string",
"serviceUrl": "string",
"id": "string"
}
The fact that it didn't suggests to me that that's where the problem is (although full disclosure, I wasn't able to re-create it).
Looking at your "members" array, I see you added the bot. I'm not sure, strictly speaking, that a bot is a member (I think members are human, but I can't find a good definition). So, my best suggestion would be to remove the bot from the members array in that second API call.
Good luck!
I am using the gmail API to get recent hangouts messages/threads. But I can't find a way to view the recipient address. The only field in payload.headers is 'From'
code:
curl -H 'Authorization: Bearer **accessToken**' 'https://www.googleapis.com/gmail/v1/users/me/threads/**threadId**?q=is%3Achat'
response:
{
"id": "xxx",
"historyId": "1008967",
"messages": [{
"id": "xxx",
"threadId": "xxx",
"labelIds": [
"CHAT"
],
"snippet": "+Harry Howard",
"historyId": "1008953",
"internalDate": "1481641738948",
"payload": {
"partId": "",
"mimeType": "text/html",
"filename": "",
"headers": [{
"name": "From",
"value": "xxx"
}],
"body": {
"size": 13,
"data": "K0hhcnJ5IEhvd2FyZA=="
}
},
"sizeEstimate": 100
}]
}
In the case of emails, there is a 'To' field ( and sometimes cc etc).
FYI: I am using node-gmail-api npm module but just testing this with curl
Use Users.threads:list to find all users within a thread. See an example here.
HTTP request
GET https://www.googleapis.com/gmail/v1/users/userId/threads
This request requires authorization with at least one of the following scopes
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.metadata
Response
If successful, this method returns a response body with the following structure:
{
"threads": [
users.threads Resource
],
"nextPageToken": string,
"resultSizeEstimate": unsigned integer
}