I build this google API client object,
serivce=build('gmail', 'v1', credentials=credentials)
i succed in founding the gmail address by doing this
serivce.users().getProfile(userId='me').execute()['emailAddress']
but I didn't found a way to get the Gmail user profile photo .
first- I tried to get it from getProfile but it only have history and other attributes.
then I tried some versions like getPhotos()/photos/getUrlPhoto but the service object doesn't have those attributes.
I would like to know how can I get from this object the user profile photo.
The Profile for a Gmail user contains the following information:
{
"emailAddress": string,
"messagesTotal": integer,
"threadsTotal": integer,
"historyId": string
}
Unfortunately, the profile photo is not one of them.
To retrieve a profile picture, you need to use the People API
Use the method people.get
Specify a resourceName (e.g. people/me) and set personFields to photos
This will return you the url(s) of the user's profile picture(s).
The response will look as follows:
{
"resourceName": "AAA",
"etag": "BBB",
"photos": [
{
"metadata": {
"primary": true,
"source": {
"type": "DOMAIN_PROFILE",
"id": "AAA"
}
},
"url": "https://lh3.googleusercontent.com/a-/CCC=s100"
}
]
}
Related
I have 2 APIs from my existing project. Where One provides the latest blog posts and another one provides sorting details. The 2nd API (sorting) gives blog posts ID and an ordering number, which should be in the 1st,2nd,3rd...n position. If I filter in the first API with that given ID I can get the blog post details.
How can I create a Django REST API from Database? or an API merging from that 2 APIs? Any tutorial or reference which might help me?
Frist API Response:
{
"count": 74,
"next": "https://cms.example.com/api/v2/stories/?page=2",
"previous": null,
"results": [
{
"id": 111,
"meta": {
"type": "blog.CreateStory",
"seo_title": "",
"search_description": "",
"first_published_at": "2022-10-09T07:29:17.029746Z"
},
"title": "A Test Blog Post"
},
{
"id": 105,
"meta": {
"type": "blog.CreateStory",
"seo_title": "",
"search_description": "",
"first_published_at": "2022-10-08T04:45:32.165072Z"
},
"title": "Blog Story 2"
},
2nd API Response
[
{
"featured_item": 1,
"sort_order": 0,
"featured_page": 105
},
{
"featured_item": 1,
"sort_order": 1,
"featured_page": 90
},
Here I want to create another API that will provide more details about sorting for example it will sort like this https://cms.example.com/api/v2/stories/105 and catch Title, Image & Excerpt and If there is no data from Sorting details it will show the first API's response by default.
After searching, I found that you can make API from Database. In setting you need to set the database credentials and then need to create a class inside your models.py and inside class's meta you need to set meta name to db_table and then create serializers.py and views.py as you create REST API.
class SortAPI(models.Model):
featured_item_id = models.IntegerField()
sort_order = models.IntegerField()
title=models.TextField()
first_published_at=models.DateTimeField()
alternative_title= models.TextField()
excerpt=models.TextField()
sub_heading=models.TextField()
news_slug=models.TextField()
img_title=models.TextField()
img_url=models.TextField()
img_width=models.IntegerField()
img_height=models.IntegerField()
class Meta:
db_table = 'view_featured'
I've implemented Stripe checkout on a Django app and it's all working correctly except that it's not showing up on the Stripe Dashboard, even though it's showing in the event data on the same page. Have I formatted it incorrectly or am I overlooking something obvious?
This is how I added meta data:
checkout_session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items = line_itemz,
metadata={
"payment_type":"schedule_visit",
"visit_id":visit_id
},
mode='payment',
success_url= 'http://localhost:8000/success',
cancel_url = 'http://localhost:8000/cancel',)
Here is a screenshot of the Metadata section empty, but in the events the Metadata is there as it should be:
Again I can access the metadata every where else but would like it to show up on the dashboard so my team can more easily access that information.
The metadata field you set is for Checkout Session alone, but not on Payment Intent (which is the Dashboard page you are at). To have metadata shown at the Payment Intent, I'd suggest also setting payment_intent_data.metadata [0] in the request when creating a Checkout Session.
For example,
session = stripe.checkout.Session.create(
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
line_items=[
{
"price": "price_xxx",
"quantity": 1,
},
],
mode="payment",
metadata={
"payment_type": "schedule_visit",
"visit_id": "123"
},
payment_intent_data={
"metadata": {
"payment_type": "schedule_visit",
"visit_id": "123"
}
}
)
[0] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
I am fairly new to python and mongodb and I'm facing an issue already.
I am trying to "translate" a nodejs backend restapi into flask, using mongodb as a data source.
Using the flask documentation, I was able to configure my app in order to connect to my local mongod.
And I am able to obtain values from the users collection like this
def getUser():
usr = Users.objects(email="mail#mail.com")
return {
"user": usr,
}
Which returns the following JSON when I'm calling the API through Postman
{
"user": [
{
"__v": 0,
"_id": {
"$oid": "5da86dc651eac87d2a82e2e2"
},
"createdAt": {
"$date": 1571319238918
},
"email": "mail#mail.com",
"password": "$2b$10$hoH57R5GL1MrwqpuW4yEJ.wwLlyNgyfxQm2Mxb19wioYTPPsU9z7y",
"profil": {
"_id": {
"$oid": "5da86dc651eac87d2a82e2e3"
},
"checked": false,
"clapList": [],
"followerList": [],
"followingList": [],
"playpoint": 0
},
"updatedAt": {
"$date": 1571319477959
}
}
]
}
As you can see, I have an array with one user in it. When I try to get only one object, like this:
def getUser():
usr = Users.objects(email="mail#mail.com").first()
return {
"user": usr,
}
I have a 500 status returned in Postman and the following error in my debug console: mongoengine.errors.FieldDoesNotExist: The fields "{'__v'}" do not exist on the document "Users"
This is my Users model
import mongoengine as me
class Users(me.Document):
phone = me.StringField()
email = me.StringField()
password = me.StringField()
accountType = me.StringField()
createdAt = me.DateTimeField()
updatedAt = me.DateTimeField()
profil = me.EmbeddedDocumentField(Profil)
I have already tried adding __v as an InfField(), but I still have the same error.
What is that __v anyway and should I retry making a new database from scratch?
Additional info:
The mongodb database and collection was generated using the nodejs API
The users in the database were generated using the nodejs API
So I added a meta property to it and I'm now able to use the class
meta = {
'strict': False,
}
I don't really know yet what transpired in there but I'm not touching anything if it works
I have parsed the friends data from the graph api and now I have the "friends" data which include the id of the friends.Now I am looking for a way to find users by the id, to add the User objects to each other as friends.
I know how to find one user's uid.
user = User.objects.get(......)
user.social_auth.get(provider='facebook').uid
But how do I find User object by the uid?
You can just do a Request on URL:
https://graph.facebook.com/<UID>
{
"id": "358204548",
"first_name": "someName",
"gender": "male",
"last_name": "someLastName",
"locale": "en_US",
"name": "John Doe",
"username": "john.doe"
}
What you want is the User object, not the user info, right?
I can't find it in any documentation, so I am not sure what's the best way to do it. But I found that this is how social_core get the user object during the login proccess: https://github.com/python-social-auth/social-core/blob/df861e886f6984f813c1f1c5c9a0acffbe719e0d/social_core/pipeline/social_auth.py#L19
So this works for me:
from social_django.models import UserSocialAuth
user = UserSocialAuth.get_social_auth('facebook', uid).user
Hope this helps
We are working with Google Drive and Permissions API to get e-mail addresses of users with sharing permissions. The API might not return the e-mail address if user forbids this in Google+ profile.
The documentation to Google Drive Permissions API says:
The email address of the user this permission refers to. This is an output-only field which is populated when the permission type is user and the given user's Google+ profile privacy settings allow exposing their email address.
After few hours of searching, we cannot find this "profile privacy settings" in question. Google Account Settings shows no such field.
Anybody knows where it is?
With "profile privacy settings" they mean that the Google + profile have shared the email from the contact information with the profile you are authenticated for the request.
I've made some test with a couple of documents, both shared with "Anyone with the link can view", but the first is from a user that shares with me the email in contact information.
Using the Try It I get the following result:
{
"kind": "drive#permission",
"etag": "\"SQFIsIrlQ4j3H07nwR6GyVXbP4s/4mfL2lpQkyuoRKmfVUHuvQuo5DI\"",
"id": "yyyyyyyyyyyy",
"selfLink": "https://content.googleapis.com/drive/v2/files/1ypzfcjfxIusRz0rLoDYh49DqPUj9DdZJI3lCGLtCkn8/permissions/yyyyyyyyyyyyy",
"name": "NAME Surname",
"emailAddress": "KKKKK.XXXXX#gmail.com",
"domain": "gmail.com",
"role": "owner",
"type": "user",
"photoLink": "https://lh4.googleusercontent.com/-DRgxkD0Vigg/AAAAAAAAAAI/AAAAAAAAZ0g/dszVFwA6bUo/s64/photo.jpg"
}
The second file is from a test account that doesn't share the email with me.
And I get the following:
{
"kind": "drive#permission",
"etag": "\"SQFIsIrlQ4j3H07nwR6GyVXbP4s/eUBKpMiVeQhLf3_Rf4Us5qisOqU\"",
"id": "ooooooooookkkkkkk",
"selfLink": "https://content.googleapis.com/drive/v2/files/1IpGtyYgJ_K6b0Xp2TWuYrcCTfPrIGJoUrStMPCyWGgM/permissions/kkkkkkkkkk",
"name": "lkajdlkj oiuaoiuoi",
"domain": "gmail.com",
"role": "owner",
"type": "user",
"photoLink": "https://lh3.googleusercontent.com/-SUCY0jPNqsA/AAAAAAAAAAI/AAAAAAAAMEk/8Y7SD9VNhHE/s64/photo.jpg"
}
As you can see the emailAddress is not displayed in the second result
To change this setting in your Google+ profile follow this steps (or the official help page):
Go to your account on https://plus.google.com
When the page is loaded in the top left corner, hover to the Home Menu
Click on Profile
Open the About tab of your profile (top center)
Scroll down to the Contact Information and click edit
Home and Work contacts can be shared to different circles or remove all the circles to make the contacts fully private