Twitter API: when and how long is media_id safe to use after media upload? - sttwitterapi

In order to save bandwidth, I try to reuse the media_id that the twitter API returns for multiple tweets, preferably indefinitely. This works, after an upload I can use the same id multiple times, but as soon as when I for example delete a tweet that uses that specific media_id, the id seems to be invalidated and the API returns a
[324] Invalid media status
This made me go on a search for how long and when these media ids are actually usable. I found nothing. Is there anyone with some experience in this field?

Related

Firestore get document except some fields [duplicate]

This question already has answers here:
How can I write a firebase rule to allow reading only part of a collection/document? [duplicate]
(1 answer)
How to allow only particular fields of a firestore document to be accessed publicly
(2 answers)
Firestore security rules for public and private fields
(2 answers)
Closed 2 years ago.
I want to get a Document from Firestore, but just with some fields of the doc.
I found 2 use cases for this. One of these is:
Users in Firestore
UsersCollection
UserDocument
email
uid
photoUrl
name
If I want to make a chat with all of the users in the users collection, I need to get all the docs in the user collection. But these docs contain some important info that's not useful to our chat, like the e-mail. Can't I just request from firebase the user document without the e-mail field? Can't a hacker find the user document in memory and get their e-mail? The e-mail is not useful for the chat, I only need the name, uid and photoUrl, the e-mail is no use for this feature, but I still get it with the whole document.
How do I "except" or get the document without the e-mail? This is more about security and user privacy.
Another use case for this would be a like system. Let's say we have a post structured like this in firebase:
PostsCollection
PostDocument
number of likes
arrayOfUsersThatLiked
photoUrl
number of likes is incremented by a cloud function that when arrayOfUsersThatLiked is modified, the function adds the length of the array in the number of likes field.
(arrayOfUsersThatLiked is used to not let the user like more than 1 time, so if someone liked the post, arrayOfUsersThatLiked will keep track of who and will not let them like again)
When we get the post document from the db, we will actually get that usersThatLiked array with a lot of uids along with the things that we need, we only need the photoUrl and the number of likes on the post, not the usersThatLiked array. (it would be a pain also to store such a huge string array).
So the main question remains, how do I only get the document with only the fields that I want to? It's a matter of privacy/security and performance.
With the Client SDKs (including the FlutterFire plugin) it is not possible to get only a subset of the fields for a Document. When you fetch a Document you get it with all its fields.
Here are three possible approaches:
Dernomalize your data: You create another collection which contains documents that only have the fields you want to display in the front end. The complexity is that you need to keep the two collections in sync: when you create/modify/delete a doc in the master collection, you need to update the other collection. This can be done from your front-end (e.g. you write to the two collections in a batched write) or with a Cloud Function, triggered in the back-end with an onWrite trigger. In terms of security, you open read access only to the second collection, not to the master one.
Use the Firestore REST API: With the REST API you can use a DocumentMask when fetching documents, which will "restrict a get operation on a document to a subset of its fields. ". Note, however, that a "hacker" could get the collection ID and fetch the documents without the Mask.
Use a Cloud Function to access the Firestore documents. With a Cloud Function, you have full control on what you want to send back to the front-end, since you query the collection from within the Cloud Function and build the response in the Cloud Function. However, using a Cloud Function instead of a Client SDK has several drawbacks: see this article for more details.

Using Matomo API to get top 10 visited pages starting with a certain URL

For a weblog I am trying to get the top 10 popular posts from for example the last month. I figured I'd get the data out of Matomo, as that's already tracking visits and has an API. I've never used this API before though, so I've been reading the documentation and trying out some things. I am able to get data from the API using the Actions.getPageUrls method. However, when I try to filter using segment=^http://example.org/post I still get data from other URL's. It looks like it filters on session and gives back all data from the sessions that have at least 1 page that conforms to the filter.
The full URL I'm using is: http://example.org/matomo/index.php?&module=API&token_auth=12345&method=Actions.getPageUrls&format=json&idSite=1&period=month&date=today&expanded=1&segment=pageUrl%3D%5Ehttp%253A%252F%252Fexample.org%252Fpost. I've also tried with less and no URL encoding for the segment, but that doesn't seem to make a difference. If I use a URL that doesn't exist I get an empty array returned.
Am I doing something wrong? Is there a different way to only get the top pages with a URL starting with http://example.org/post? Or do I have to sift through the data myself to only get the pages I want?
I am using Matomo version 3.13.5.
I figured it out. There is no need to use segment. This can be achieved using the flat, filter_column and filter_pattern parameters.
Setting flat=1 will make it so all pages are returned in a single array, instead of hierarchically.
With filter_column and filter_pattern I can filter the results.
The URL I use now is: http://example.org/matomo/index.php?&module=API&token_auth=12345&method=Actions.getPageUrls&format=json&idSite=1&period=month&date=today&flat=1&filter_column=label&filter_pattern=%5E%2Fpost%2F. This does exactly what I want.
The unencoded pattern is ^/post/, so this will filter out any page that does not start with /post/.

Axios requests ignoring parameters

I am sending requests to the the Firebase Realtime API. When I try to delete an from item within from a specific collection (e.g. journals) and specify which journal title using axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: "Nature"}}) all of the journals in the collection are deleted, not just "Nature". Similarly, if I do a get request and specify a title, all journals are returned.
I have also tried using "https://topxxx-xxx.firebaseio.com/journals.json", {params: {title: "Nature"}}. but that also returns all journals. Here are an example delete request:
axios.delete("https://topxxx-xxx.firebaseio.com/journals.json", {title: this.state.title})
.catch(error=> console.log("Error" + error))
The Firebase Realtime Database API doesn't support conditional deletes. To delete a node, you must specify the entire part to that node, and (in the REST API) either use the DELETE verb or use the X-HTTP-Method-Override: DELETE header.
So the two step process:
Perform a query to find the nodes with the title you're looking for:
https://topxxx-xxx.firebaseio.com/journals.json?orderBy="title"&equalTo="the title"
Delete the matching nodes by sending a DELETE to URLs like:
https://topxxx-xxx.firebaseio.com/journals/journalId1.json
You cannot delete a specify item from a json file like that in firebase, and also using GET will return the entire collection. It is working amazingly correct from firebase side. If you want something like how you are expecting, go for a small flask server or checkout cloud functions in firebase
You probably want to send that request to a back-end services that's connected to firebase (i'm assuming since you're using axios). Then call the remove method as demonstrated here

Using google search api cursor in angular js app to get all results for google patent search

I want to make a search into google patent using the following URL which is obsolete
https://ajax.googleapis.com/ajax/services/search/patent?v=1.0&q=thumb%20wrestling%20apparatus&userip=192.168.1.102
It gives me limited number of records per page.
But at the end of the JSON it also returns the cursor which has start and label keys. So my question is that how can I use that cursor to show all the records in my search. Like if there are 8 pages and each page contains 4 records so I want to show all 32 records on my UI.
How can I achieve that?
And second question that is there REST APi for google patent search? If yes then how can I search the patent using REST API and how can I get all the records on one page?
It looks like the API is restricted to a maximum of 8 results per request (you can increase your current 4 results to 8 by using the query param rsz=8.
So I guess the only way to get all results is by performing multiple requests. So if the current page info data is...
"pages":[
{"start":"0","label":1},
{"start":"8","label":2},
{"start":"16","label":3},
{"start":"24","label":4},
{"start":"32","label":5}
]
You would make 5 requests chaining the start param start=0, start=8 ... and so on, extracting the results and pushing to an array store. If you're not already I recommend using something like Restangular, as it would make this process much easier.
Depending on how your UI is set out, it would be nice maybe to do this with some lazy loading as the user is scrolling through the list?

Manipulating Soundcloud Stream with Chrome Extension Content Script

I am writing a Chrome extension using AngularJS to add functionality to the Soundcloud stream page. I want to allow the user to create groups of artists so that they may only see a stream with tracks/shares/playlists from that group of artists.
For example, I follow 500 artists, but I want to quickly see a stream from my favorite 10 artists or from the artists I follow that are on the same label.
I am looking for advice on how I could go about making this as seamless as possible. As of right now, my approach involves getting the tracks with the Soundcloud API and using angular's ng-repeat to display the tracks in a view injected into where the stream normally goes. I realized using the Soundcloud widget was too slow and can't be customized to resemble the native stream items, so I copy/pasted the HTML that an actual stream item uses, but obviously the waveform/comment canvas and button functionality don't work.
What are my options as far as how I can approach this? Am I going to need to write my own players that look like the native Soundcloud ones? Any suggestions would be greatly appreciated.
You should use the SoundCloud API which is very well documented.
If you have already the id's of the tracks / artist, you just have to request the url
GET
http://api.soundcloud.com/tracks/ID_OF_TRACK.json?client_id=YOUR_CLIENT_ID
to get all the informations you need about this track, like the waveform_url, and for the comments you was talking about :
GET
http://api.soundcloud.com/tracks/ID_OF_TRACK/comments.json?client_id=YOUR_CLIENT_ID
To reproduce the behaviour of the comments :
POST http://api.soundcloud.com/tracks/ID_OF_TRACK/comments.json?client_id=YOUR_CLIENT_ID
(with a body param which represents the text and a timestamp in ms since the beginnin of the song, note that you must be connected)
If you don't have the id of the track, you could also use the resolve which give you all the info about a ressource if you have only the URL :
GET
http://api.soundcloud.com/resolve.json?url=https://soundcloud.com/poldoore/pete-rock-c-l-smooth-they&client_id=YOUR_CLIENT_ID

Resources