When I request my user data from localhost:8000/users, I get users that look like this:
{
"username": "iv4ha05k",
"email": "xxxx#xxx.com",
"profile": {
"image": "http://localhost:8000/media/images-4.jpg"
},
"pk": 303
},
But, if I request user data from the django manage shell, the data will look like this:
{
"username": "iv4ha05k",
"email": "xxxx#xxx.com",
"profile": {
"image": "/media/images-4.jpg"
},
"pk": 303
},
Notice how the image url becomes truncated. I am querying the same exact database in the same exact state, and it has nothing to do with migrations or anything of the like. I discovered this issue when trying to write custom API views. When I would query the User viewset, it would return data with the full image address. But, when I try to write a custom API view that queries the user database, it will return it with the truncated address. I am using django's FileSystemStorage, if that helps anyone.. Thanks.
Related
I am using the tweepy library to retrieve user bookmarks, but I am unable to retrieve the profile picture URL despite passing the correct user_field.
According to the tweepy documentation, the only available expansion for this endpoint is "expansions=owner_id". I am not sure what this means or how to retrieve the profile picture URL.
Can someone help me understand this and provide a solution?
bookmarks = client.get_bookmarks(expansions=["author_id"],
user_fields=["profile_image_url"])
The response object is as follows:
{
"data": [
{
"id": 1621356248334483456,
"text": "The majesty of nature is on full display at Yosemite National Park. Visit now to experience it for yourself: https://natureloversparadise.com"
},
{
"id": 1620813010569945091,
"text": "Discover the beauty of the Great Barrier Reef with a snorkeling adventure. Book now at https://greatbarrierreefadventures.com"
}
],
"includes": {
"users": [
{
"id": 123456789,
"username": "naturelover",
"name": "Nature Enthusiast"
},
{
"id": 987654321,
"username": "oceanadventurer",
"name": "Ocean Adventurer"
}
]
}
}
As you can see, the includes section only contains basic information about the authors of the tweets (id , username , and name ), and no information about profile pictures.
Thank you for your help.
I have successfully made the necessary scope access and authentication. However, I think the get_bookmark() method might only return basic author information like author_id user fields and need confirmation before using user_id to call user information from different method.
Is there a way to modify these fields through the Admin SDK without manually doing it through the admin console? Specifically under the employee information, the job title, type of employee, manager's email and department.
I've looked at https://developers.google.com/admin-sdk/directory/reference/rest/v1/users and https://googleapis.github.io/google-api-python-client/docs/dyn/admin_directory_v1.users.html#insert but I don't see any parameter that you can specify these fields in.
Any help would be appreciated, thank you!
The fields are kind of scattered around but we can figure it out by filling them manually on a test user and running a users.get on them.
So for an employee that looks like this:
The API result is the following (after removing the irrelevant fields):
{
"externalIds": [
{
"value": "ID-123",
"type": "organization"
}
],
"relations": [
{
"value": "example#domain.com",
"type": "manager"
}
],
"organizations": [
{
"title": "My Job Title",
"primary": true,
"customType": "",
"department": "My Department",
"description": "My Employee Type",
"costCenter": "My Cost Center"
}
],
"locations": [
{
"buildingId": "My Building ID",
"floorName": "My Floor Name",
"floorSection": "My Floor Section"
}
]
}
So from this we can deduce that Job Title corresponds to organizations.title, Type of employee corresponds to organizations.description, Manager's email corresponds to relations.value that also has a relations.type = manager and Department corresponds to organizations.department.
Do note that as explained in the documentation that you were looking at, these fields can hold multiple values, so the user can have multiple organizations, but the one that shows in the Admin console is the one marked as primary, they can have multiple relations other than manager such as assistant, spouse, etc. They can have multiple locations and so on.
Generally what will be displayed in the Admin console are the primary fields. Any secondary values may not show up but you can still retrieve them via the API. Most likely they're meant for custom applications that can take advantage of reading these multiple fields, while the console only shows the most relevant fields (as decided by Google).
I know I am not the first person to ask this question, but I still couldn't find an answer for my situation.
I have a Django environment that works very well, I know I only have one (1) settings.py file and I know that my environment accesses it correctly.
I recently added a new endpoint to my project. I defined its URL in urls.py
urlpatterns = [
...
url(PREFIX + r"^v1/alerts/debug$", alerts_views_v1.debug_trigger_alert_notification),
...
]
It is connected to a method that is in a the file alerts/views_v1.py but is not in any particular class:
#api_view(["POST"])
def debug_trigger_alert_notification(request):
"""
Trigger an Alert. i.e. Create an Alertnotification.
This function is meant to be called by the scheduler service.
"""
workspace_slug = request.data.pop("workspace")
with in_database(workspace_slug, write=True):
serializer = AlertNotificationSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response()
When I send a request to this URL, I receive the following 500 error:
ImproperlyConfigured at /v1/alerts/debug
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
In my settings.py file, my DATABASES variable seems correct (though it is built in a roundabout way):
DEFAULT_DATABASES = {
"default": { # This DB is supposed to always have the latest version of the schema described by the Django Model
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["REFERENCE_DB_NAME"],
"USER": os.environ["DB_USER"],
"PASSWORD": os.environ["DB_PASSWORD"],
"HOST": os.environ["DB_HOST"],
"PORT": os.environ["DB_PORT"],
}
}
# Retrieve all existing workspace databases:
try:
_existing_workspace_database_names = ExistingWorkspace(
db_user=DEFAULT_DATABASES["default"]["USER"],
db_host=DEFAULT_DATABASES["default"]["HOST"],
db_password=DEFAULT_DATABASES["default"]["PASSWORD"],
).list_existing_workspaces()
except Exception as e:
log.critical("settings.py: Error retrieving list of existing databases.")
raise e
else:
log.info("settings.py: Successfully retrieved list of existing databases.")
WORKSPACE_DATABASES = {
db_name_to_slug(existing_workspace_database_name): {
"ENGINE": "django.db.backends.postgresql",
"NAME": existing_workspace_database_name,
"USER": os.environ["DB_USER"],
"PASSWORD": os.environ["DB_PASSWORD"],
"HOST": os.environ["DB_HOST"],
"PORT": os.environ["DB_PORT"],
}
for existing_workspace_database_name in _existing_workspace_database_names
}
DATABASES = {**DEFAULT_DATABASES, **WORKSPACE_DATABASES}
DATABASE_ROUTERS = ["dynamic_db_router.DynamicDbRouter"]
What can I do?
Pardon for such vague question. I have a URL http://example.com/graphql. I want to know what operations are available. Is there anyway to find it out?
GraphQL has the introspection system which allow you to query its schema.You can construct GraphQL query to explore its types.
For example ,to find out all the query and mutation root fields , you can POST the following JSON body to http://example.com/graphql with content type set to application/json
{
"query" : "{__schema {queryType {name fields {name}}mutationType {name fields {name}}}}"
}
Or using GET and putting the GraphQL query to the query parameter query :
http://example.com/graphql/?query={__schema {queryType {name fields {name}}mutationType {name fields {name}}}}
which will return something likes:
{
"data": {
"__schema": {
"queryType": {
"name": "Query",
"fields": [
{
"name": "searchFoo"
},
{
"name": "searchBar"
}
]
},
"mutationType": {
"name": "Mutation",
"fields": [
{
"name": "createFoo"
},
{
"name": "updateFoo"
}
]
}
}
}
But the much easier way is to use a GraphQL client such as GraphiQL or Insomnia or ..... which most probably will provide you an interactive UI to exploring the GraphQL Schema and has some auto-complete/hint feature for assisting you to construct the GraphQL query.
I am making a small app which requires login functionality. I am using flask for making api's and flask-security to have login feature.
Login feature is working fine, but I need response object in some customised form.
Right now I am getting response object as:
{
"meta": {
"code": 200
},
"response": {
"user": {
"authentication_token": "some token",
"id": "some id"
}
}
}
I need output in some customised form which will be:
{
"meta": {
"code": 200
},
"response": {
"user": {
"authentication_token": "some token",
"id": "some id",
"role": "some role"
}
}
}
I want role of the user along with response. I saw flask-security-config but didn't get any way to do so.
Is there any way, in which I can get this desired behaviour either by changing some config of flask-security or writing some wrapper function on top of this api.
Any useful suggestion will be very helpful. Thanks!