Tracking tweet in realtime with tracking terms changing - javascript

I want to build an application that allow users to set a hashtags or mentions that they want to track from their dashboard, and my api will open a web socket to display the tweets in realtime at client side.
If I use twitter streaming api, I need to close and reopen the connection every time user change or add a tracking term. This seems not good, and not scale well.
Is there a better approach for this problem? Please advise.

Related

Sending RealTime Notifications Based on Location in NodeJS

I’m building an app with some location-based requirements. One of the requirements is to send the user a notification whenever the user is at a specific address (think of it like how the Apple Wallet app sends you a notification whenever you get close to, say a Starbucks location).
How would I go about building this kind of functionality? I’m aware that this will require using WebSockets. But, like, how would I do this exactly?
Do I just have the client send his geo coordinates to my backend every time it changes, then compare that to a desired destination saved on a database? Or, is there a better way?
Thanks.

How do I push mongodb data?

So I have developed a web app as a hobby on Handlebars, Express and Mongoose/MongoDB.
The app let's users create an account and then post advertisements for other users to see and respond to.
All the ads posted by users show up on the index page. So it is common view for all the users on this web app. I am relatively new to web development so to build such a simple app it took me a while but boy I learned a lot!
Now the issue I am facing is, when a user A posts an Ad while the user B is logged in and is currently on the index page (a page that lists all the ads posted) it won't show up for user B unless user B refreshes the page. Rightly so actually because only when the index page's route is hit it will query all the ads and refreshing is basically hitting the index route I get that. But I don't want it that way. I want it to show the new ad on user B's index and pretty much every user's index if there's new ad by any user.
So I did a little research/reading and I learned that I can do it by learning to work with triggers on mongodb and like create some kind of trigger that when a new ad is posted do something. I like the idea but failed to find resources to learn how to use such a thing.
The other option I was suggested was to use socket.io but that too I can't grasp how can I make an entire Ad document work as a socket. I am lost and implementing this feature of dynamically loading ads for all users will complete this hobby project of mine and will help me find a junior dev job in local community.
I request stackoverflow's community to guide me how do I go about doing this and what resources I can use to learn about it.
The socket.io seems to be the best solution for your case. What you will want to do with socket.io is every time a user posts an Ad you use socket.io to notify the rest of the users that there is an update.
If you don't want to send the entire document using the socket you can use the socket to notify the clients and on the client side every time you receive such a notice from the server you will either
a) Refresh the page(not suggested as it will make the user experience unpleasant) which is easier to implement
OR
b) You can use an Ajax request to get the new data from your server and update the fields on the fly(which makes for a better user experience).
Best Way You can come with using Short Polling concept from client side to ask for new data after 1 or 2 seconds (whatsoever count to need ) . Gmail for new inbox mails also uses sync method in a particular fashion . Just ask from server for new data
OR Second option to go through below
On Server Side
Serve index.html page to User A (which is logged in now).Some User B inserts data
Maintain a function or a cron job (checks the count of Total Ads ) Lets say after every 1 minute or so
If there is change in count from the previous total_count , update it and get new mlab documents and send it to function , Let's say push_new_ads which will be sync via socket.io to client
On Client Side
Sync your client_total_count with server_local_count push_new_ads using socket.io and If there is change in count , make a simple fetch api call to get data and appends it to previously fetched array
There is no such way to directly listen the changes in mongodb But you can trigger some changes from oplog using tailable cursors

JavaScript - Button Click to send data remotely

I have a list of company tablets (Android) that are located all around the United States. I would like to be able to select one from a list, compose a message, then be able to send the message to the selected device. Some locations have multiple tablets on the same network, in which i'd like to send to all of them at once if possible.
Is it possible to send data over the internet via JavaScript to an android device, or a list of devices? If so, how can this be done? Is there a certain term for what I am trying to do so I may google this for better results?
I apologize for my lack of knowledge and terms.
There's two options you have:
1. Use websockets to send messages to active devices
In your backend system (you need one) keep a list of active connections. In your webpage, display the connections. Select one, and in an input field type a message. Send this message to the backend, e.g. form post, and send this message to the corresponding connection. In your active device, have an app working that listens to the socket and displays the message.
2. Use Push notifications
You can easily send push notifications to android devices. However, you need a working app on a device before you can send it pushnotifications. Firstly, the app needs to register itself at GooglePlayServices, there's a ton of tutorials on this. Then this will give the app a deviceId, which it needs to send to your backend. In your backend you keep track of all deviceIds in your database.
The same principle holds for alternative 1: display the deviceId's in your listbox, and send it together with a message to your backend.
In the backend send a push notification to the device. There's also a ton of tutorials on how to do that (you need to set up a project in Google to get an API key, which is really easy).
There are probably other alternatives, but these two are the most easy I'm sure.
Also, in order to group send notifications, group devices by their external IP. Make the devices register themselves to your backend so you have their external IP, then group them by that in your database. In the frontend now select an IP instead of a device.
EDIT by FoxDonut (Asker)
I also asked, in the comments below, if it is possible to use push notifications without uploading my application into the Google Play Store. The answer is Yes. Please see this post for clarity.

Automatically access my Google Analytics and display chart publicly on my website

I'm having some difficulties in figuring out the best way to do this:
Using Google Analytics API, or similar Google API, I would like to track a user's activity from the moment they access the page until they reach an end page, which is gonna show them back some charts with THEIR activity on my website. (Nothing too detailed, just how long they've been on each page, how many session etc.)
So far, I've managed follow the Embed API example to access THE USER's Google Analytics account and draw a chart by asking for permission, however when it comes to showing data from MY account I just can't seem to figure it out.
I want my website to automatically use my account (or service account) and draw some charts from my google analytics data and show it to every user.
What would be the best way to approach this? I've read something about access tokens but I don't know if that's the solution. Moreover, my hosting is a shared host and I don't think it allows installing Python Modules like in this example.
Cheers for the help!
If you want to show the user your data, you will have to perform the authentication on the server side. There is no way around this. It is after all, your account's data that they are accessing.
If you are unable to install Google's client library, you need to:
Get an access token using cURL (see how here)
Use that access token to perform server side authentication for the user (see how here)
The user should now be able to access your site without logging in, and see YOUR data.

YouTube API | Javascript- Upload video to a constant channel bypassing login.

I'm building a web application that allows a specific user to upload videos to a YouTube account through the use of the YouTube API. The uploading of videos will be done by only one person & videos will be uploaded only to one account. If the YouTube account is already authorized by the app to manage the channel etc, how can I setup the application in such a way that the user bypasses the authentication/login screen every time he/she needs to upload a video? (That is when the user exits and re-enters application.)
While reading, a solution I stumbled upon a solution which was to use a refresh token but I don't know how to integrate it with the code I have currently. The code I'm using is the one available on the Google Developers site, link below.
https://developers.google.com/youtube/v3/code_samples/javascript#upload-a-video
Please note that I've gone through & read all similar questions on this forum but none provides Javascript help/solution.
Normally i would say that you should use a service account which would allow you to preauthorize the access to YouTube. However the YouTube API does not support service accounts so your going to have to do it the hard way.
You will need to authenticate your application once and save the refresh token. Then you will be able to use the refresh token again later to get a new access token. You will have to watch this application refresh tokens can expire its rare but it can happen so you should have something set up that will allow you to quickly reauthenticate it and save a new refresh token.
To my knowledge it is not possible to get a refresh token with JavaScript your going to have to use a server sided language like node.js for example. This tutorial should show you how to get offline access with node js. Node.js Quickstart

Categories

Resources