'Twitter API V2 video url
I'm trying to fetch a tweet's video url using API V2.
Using API V1.1 I can use
https://api.twitter.com/1.1/statuses/show.json?id=<ID>&include_entities=true
and get the direct mp4 urls in the response at
extended_entities.media[0].video_info.variants
But using API V2 I can't seem to find any ways to get those, I was only able to get the video thumbnail but not the actual video.
I've tried it with both the lookup and the recent search endpoints but couldn't find a way to do that.
In lookup docs twitter says:
This endpoint was recently graduated from Twitter Developer Labs, and is the replacement of v1.1 statuses/show, v1.1 statuses/lookup, and Labs Tweet lookup. If you are currently using any of these endpoints, you can use our migration materials to start working with this new endpoint.
but that doesn't seem to be the case, is that feature not included ? Also if there is any other way to be able to embed a twitter video in a web page (without the tweet text) that'd be helpful.
Solution 1:[1]
Progress on twitter-api-v2 media handling, Maybe this will allow the video URLs too in the response.
Solution 2:[2]
Maybe you can just use the built in logger? Log the moment the field you're using the lock the row changes value and the moment a user tries to edit the data-entry.
// lock data-entry and show form
public function edit(Request $request, DataEntry $dt)
{
// log attempt and lock status
Log::debug(Auth::user()->email . ' is trying to edit data-entry ' . $dt->id . ' (lock status: ' . $dt->lockField . ')');
// check if user should be allowed to edit
if ($dt->lockField != null) { /* deny attempt */ }
// update lock status
$dt->fill(['lockfield' => ...])->save();
// return edit view
}
// update data-entry and unlock it.
public function update(Request $request, DataEntry $dt)
{
// update dt fields
$dt->fill(...)->save();
// update lock status
$dt->fill(['lockfield' => null])->save();
// log lock status
Log::debug('Data-entry '. $dt->id . ' was just updated. Lock status: ' . $dt->lockField);
// return
}
This would show in your logs with timestamps. You could make sure there is a delay or if the users are being overly eager.
If you see something like
[YYYY-MM-DD 00:00:00] Data-entry 1 was updated just updated. Lock status: null
[YYYY-MM-DD 00:01:00] user@email is trying to edit data-entry 1 (lock status: not null)
Then you have a problem.
Maybe it could be user error. Are you sure they are not closing the form instead of submitting it?
If you think there is a delay in your queries, you could also try logging them through the DB facade.
// Inside AppServiceProvider@boot method. Or any other ServiceProvider really
DB::listen(function ($query) {
Log::debug([
'sql' => $query->sql,
'bindings' => $query->bindings,
'time' => $query->time,
]);
});
If you the logging part to be taken care of by a package, you could use something like laravel-auditable but I think it's not warranted for this case.
Another thing I just thought of: Are you using a cached value to return the data-entry when an user wants to edit it? If you are, make sure you are clearing the key when the lockField is updated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohammad Barjabeen |
Solution 2 |