Tastypie - get user groups resource_uri - python

I'm trying to update the groups assigned to users via an API (via rest) with Tastypie.
I tried passing the group id's directly in, however it says that the URL provided is not a valid resource. I then tried passing in a URL such as '/api/v1/groups/1/' but that is saying that's not a link to a valid resource.
Any hints? I'm creating user records just fine from a standard django view/form, but I would like to do this as a REST action.

Do you need to specify the format, such as: /api/v1/groups/1/?format=json ?

Related

How to view work item xml ids in azure ticket

I have an azure devops work item with some custom fields:
I can set some of these fields using the azure api python package, like so for 'RTCID':
jpo.path = "/fields/Custom.RTCID"
But when I try to set the targeted release, I can't find what the field path is for this variable, I've tried
jpo.path = "/fields/Custom.TargetedRelease"
But that results in an error.
I know my organization id, is there any way I can list all the variable path IDs in a ticket?
I tried going to https://dev.azure.com/{organization}/{project}/_apis/wit/workitemtypes/Epic/fields to see all the fields, but ctrl+f searching for 'targeted' brings up no results
To save the response time when calling a Azure DevOps REST API, many times it will not load the complete properties to the request body.
If you want to view more properties, you can try to use the parameter $expand to expand the complete properties.
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitemtypes/{type}/fields?$expand=all&api-version=7.1-preview.3
In addition, you also can use the API "Work Items - Get Work Item" to get a work item that is the work item type you require, and use the parameter $expand to expand all the fields.
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/{id}?$expand=fields&api-version=7.1-preview.3
This also can list all the fields on the work item type.

Facebook GraphAPI; posting to group vs page of same name

Using Facebook's GraphAPI I am trying to post to a public group. It appears that a page by the same name also exists and it is defaulting to post to that instead.
Currently I am using
posts = graph.get("NAME_OF_GROUP/feed", page=True, limit=1):
Hopefully there is a way to default it to group over page. I cannot find much in the documentation.
Only pages have a name that they are accessible by via API. A group name is "just for people", for display purposes, it was never possible to use that to access the group in API calls. So there is no defaulting of page over group going on here; if the page did not exist at all, you would still not be able to access the group this way - the group ID is the only way to do that.
And posting to a group will require an access token from the group admin these days, https://developers.facebook.com/docs/graph-api/reference/v2.12/group/feed#publish

How can I get only responses tweets?

I need to retrieve specific data from twitter.
I'd like to get all the responses tweets received by a specific user (which is not the authenticating user of the program). Is there a way to achieve this? Right now I'm thinking about using the search function and see if the 'in_reply_to_user_id_str' matches the id of the user I want.
But this means that I need to filter a lot of data to find the one I want
Edit: I'm using the Python-Twitter-Tools
If it is the authenticating user, you can directly get the response tweets using the 'mentions timeline'. As the user is not the authenticating user, you have two options here.
Streaming API
Use the filter endpoint along with the 'follow' parameter. Pass the required 'user_id' to the follow paramenter and it will return the followings. You will have to check the 'in_reply_to_user_id_str' in order to isolate the replies(responses).
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply button.
Python-Twitter-Tools supports Streaming API. Streaming API is realtime and better than Search API considering the completeness.
Search API
Every response tweet contains the "#username" tag. You can searching using "#username" tag and then filter the tweets using 'in_reply_to_user_id_str' as you have mentioned.
Considering the two options, Streaming API will help you to get what you need easily and reliably.

How to get access to the URL segments after a # in Python Flask?

I'm trying to support OAuth2 login through Python Flask, so I want to handle a URL that looks like this:
http://myserver/loggedIn#accessToken=thisIsReallyImportant
but when I handle the callback it just seems to drop all the characters after the # in the URL, which contains the important Oauth access token. How do I get this info? It's not included in request.url
ETA: I can retrieve it in client-side javascript using window.location in Javascript, but then I'd have to pass it back to the server, which feels a little hokey but maybe Oauth2 is meant to be done that way?
From the RFC:
Fragment identifiers have a special role in information retrieval
systems as the primary form of client-side indirect referencing
[...]
the fragment identifier is not used in the scheme-specific
processing of a URI; instead, the fragment identifier is separated
from the rest of the URI prior to a dereference
As such, flask drops everything after the '#'. If you want to forward these to the server, you'll have to extract them on the client and pass them to the server via a query parameter or part of the URL path.
You are using the incorrect OAuth 2 grant type (implicit grant) for what you want to do. Implicit grant supplies the token in the fragment as you observed to be used by a javascript client. There is another type of grant, authorization code, which is similar but supplies it in the URI query which you can access from Flask.
You can tell the two apart from the the redirect URI you create for authorization, if it has response_code=code you are on the right track. You currently use response_code=token.
If you are using Facebook look at https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/
For Google look at https://developers.google.com/accounts/docs/OAuth2WebServer
You might also be interested in https://flask-oauthlib.readthedocs.org/en/latest/ which can help you with OAuth.

Twitter Stream API, Parameter follow has unparseable items

Recently I'm doing a small project on twitter, and I want to get tweets from some specific users.
So I use Streaming API, pycurl and python.
The API Reference says the follow parameter is:
A comma separated list of user IDs, indicating the users to return
statuses for in the stream. See the follow parameter documentation for
more information.
And I tried this
c.setopt(c.POSTFIELDS, 'follow=slaindev')
but the return message is not the tweets that slaindev posted, but an error
Parameter follow has unparseable items slaindev
So do I misunderstand the meaning of user ID? I think it is the one we use to mention someone( I mean I use #slaindev to mention this guy).
When I try track parameter, it works fine.
Your assumption regarding user_id is incorrect. See this, for example. You are talking about screen_name.

Categories