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.
Related
I am quite new to django rest framework and I would like to discuss what is the best way to implement an API endpoints I am aiming to have.
I have following JSON example:
[
{
'top_lvl_key1': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
},
{
'top_lvl_key2': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
},
{
'top_lvl_key1': {
id: 2
'some_key1': "value"
'some_key3' : "value"
}
},
{
'top_lvl_key3': {
id: 1
'some_key1': "value"
'some_key2' : "value"
}
}
]
and I want to have 3 endpoints
[POST] /insert inserting and parsing the entire JSON to store it into models
[GET] /detail/<top_lvl_key>/ Display all record for specfici top_lvl_key
[GET] /detail//<top_lvl_key>/id/ Display a record for specific top_lvl_key and specific id (only 1 record)
As you can see, I need to store each type of top_lvl_key to different model so I can retrieve for GET requests. However I am not sure how should I got about serializing the JSON, since the dictionaries of the top_lvl_keys can differ. For example top_lvl_key_1 can sometimes have some_key_1 and some_key_2, but sometimes some_key_1 and some_key_2. So far I have been implementing the models with blank=True, null=True, but I am not sure this is best solution as there a lot of attributes which can be NULL now. Is there a better way to go about this?
Thanks a lot in advance
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).
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!
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.