How to get Mentions of other user using Linq To Twitter - linq-to-twitter

I want to get mentions of a any user using linq to twitter api. I have a code which brings back the user time line, but I want to get only mentions of a user, one of the method that is Mention Timeline can only be used to get mentions for authenticatd user but I want to get for any user. How it is possible? Here is my code which return a user timeline, what modification require in it? Please help
var mentions= await _twitterContext.Status
.Where(s => s.ScreenName== ScreenName && s.Type == StatusType.User && s.Count == 200)
.ToListAsync();

The Twitter API doesn't expose an endpoint that allows you to get mentions for any user with a screen name. However, you can get the mentions if you are authorized by the user for whom you want to get mentions for. Here's an example:
var tweets =
await
(from tweet in twitterCtx.Status
where tweet.Type == StatusType.Mentions &&
tweet.ScreenName == "JoeMayo"
select tweet)
.ToListAsync();
PrintTweetsResults(tweets);
The documentation for this is here:
http://linqtotwitter.codeplex.com/wikipage?title=Querying%20the%20Mentions%20Timeline&referringTitle=Making%20Status%20Queries%20and%20Calls

Related

How to retrieve other users from a Firebase app?

I'm learning JavaScript and I'm trying to built a social app in a specific domain. Nothing big as usual social network because it's for a small community.
So I'm using Firebase, JavaScript ES6 and only one HTML file with an <app>. I already have and auth system, profile page for the current user. But my problem is that I don't know, understand the way to have pages from other's profile.
So as far as I succeed to go it's to get the other's users information from by Firebase database. But I'm stuck in my mind. Should I create an HTML file for each user? I don't think so?
This project is for a certification.
And my other problem is and can't make a verification from data. Well I succeed to check if data exist but it doesn't block the process so it updates anyway and get 2 users with the same name (see code below).
firebase
Atom
savePrenom(event){
let database = firebase.database();
event.preventDefault();
let uid = firebase.auth().currentUser.uid;
database.ref('users').once('value', (snapshot)=>{
snapshot.forEach( el=>{
if(prenom.value === el.val().prenom){
console.log('existe déjà');
}
if (prenom.value != el.val().prenom){
savePrenom.style.display= 'none';
editPrenom.style.display= 'block';
prenom.disabled = true;
database.ref('users/'+uid).update({
prenom: prenom.value
})
}
})
});
}
To solve your first problem: Do not create a html file for each user, that's terrible!
You should rather fetch the data and then use DOM manipulation to insert your data into the page. I do not know which database you are using so I can not give you a code sample for the fetching but only one for DOM manipulations.
Let's say you have the following html:
<p id='description'></p>
You can get the element by id and change it's properties, this is known as DOM manipulation.
document.getElementById('description').textValue = 'Very important'
This assigns Very important to the paragraph (the text will appear when executed by a browser).
Since you said you use plain ES6 only, I'm not going into backend technologies like NodeJS.
I can not help you with the second one since I lack information, please submit some code and tell us more about the technologies you are using.
Ok guys sorry for not responding for all question/answers but i got both solutions.
On the first one. As i could get the informations from a user a simply add some data-classes to passe the data that i could get from firebase. But their was a easier solution. From the moment i can get any information inside a user, i could get the key of each user using snapshot.key (which i forgot). So then it's easy, using a forEach element, each link to each profil use the right information on an other page.
Second question to check if a username already existe when changed for exemple. Well, i started to make a once reference value on my database users. Then if my pseudo.value === el.val().pseudo that means it existe to error message. If not, the user can change his username if wanted with .update for firebase.
database.ref('users').once('value', (snapshot)=>{
let find = false;
snapshot.forEach(el =>{
if(pseudo.value === el.val().pseudo){
//console.log('YEAH');
find = true
}
})
if (find === false) {
savePseudo.style.display= 'none';
editPseudo.style.display= 'block';
pseudo.disabled = true;
database.ref('users/'+uid).update({
pseudo: pseudo.value
})
}
Thanks all.

wordpress - how to take user data and send it in an email

I'm stuck and the plugin owner of wp-courseware don't wan't to offer assistance with this.
I am trying to grab the wordpress user data (email and country) and then put it into a file that will send this data dynamically.
I am using wp-courseware and I have found the following code and trying to intergrate the users details (mainly country into the code)
function WPCW_actions_users_moduleCompleted($userID, $unitID,
$unitParentData)
{
if (!$userID || !$unitID || !$unitParentData) {
return;
}
$userDetails = get_userdata($userID);
// Admin wants an email notification, and email address exists. Assumption
is that it's valid.
if ($unitParentData->email_complete_module_option_admin == 'send_email' &&
$unitParentData->course_to_email)
{
$adminSubject = __("Module Complete Notification - {USER_NAME} - Module
{MODULE_NUMBER}", 'wp_courseware');
$adminBody = __("Hi Trainer!
Just to let you know, {USER_NAME} has just completed 'Module {MODULE_NUMBER} - {MODULE_TITLE}'.
{SITE_NAME}
{SITE_URL}
", 'wp_courseware');
// Do email sending now
WPCW_email_sendEmail($unitParentData,
$userDetails, // User who's done the completion
$unitParentData->course_to_email,
$adminSubject, $adminBody);
}
// Check if admin wants user to have an email.
if ($unitParentData->email_complete_module_option == 'send_email')
{
WPCW_email_sendEmail($unitParentData,
$userDetails, // User who's done the completion
$userDetails->user_email,
$unitParentData->email_complete_module_subject, // Use subject template in the settings
$unitParentData->email_complete_module_body // Use body template in the settings
);
}
// Any additional admin-level notifications?
do_action("wpcw_user_completed_module_notification", $unitParentData,
$userDetails, $adminSubject, $adminBody);
}
This would depend on how you, or the plugin you're using, is saving the Country data to the database. Check out the wp_usermeta table and look for the key under which the country is saved. Or, since the function above is already grabbing all of the user's meta with $userDetails = get_userdata($userID);, you could print the $userDetails array and see what you have to work with.
Note how the email is grabbed by using $userDetails->user_email;. It will be similar to this, using that country meta_key instead.

How do you use query parameters to limit retrieved contacts in the Google Contacts API

I'm trying to test out the Google Contacts API with JavaScript. I know that V1 had support for JavaScript but V2 and V3 don't list it. However, I have been able to find a way to retrieve contacts through an AJAX request so getting the contacts isn't really the problem right now. However, I'd like to be able to specify the search criteria of the contact that I'm looking for so that I don't have to page and search through all of the users contacts.
Right now, my code looks like this:
function getContact(domTarget) {
// Get permission and a token
auth(function(token) {
// Create an AJAX request to get the contacts
var ajaxContactRequest = new XMLHttpRequest(),
url = "";
// What to do when we get our contacts
ajaxContactRequest.onreadystatechange = function() {
if (ajaxContactRequest.readyState === 4 && ajaxContactRequest.status === 200) {
// Parse our contact data as a JSON object
var response = JSON.parse(ajaxContactRequest.responseText),
contactArray = response.feed.entry, i, contactDiv;
// Print out the contacts
if (domTarget) {
for (i = 0; i < contactArray.length; i++) {
if (contactArray[i].title && contactArray[i].title.$t) {
contactDiv = document.createElement("div");
domTarget.appendChild(contactDiv);
// Print out the contact's name
contactDiv.innerHTML = contactArray[i].title.$t;
}
}
}
}
};
// Construct our URL
url += "https://www.google.com/m8/feeds/contacts/default/full/";
// Add the access token
url += "?access_token=" + token.access_token;
// Get JSON format back
url += "&alt=json";
// Limit to 10 results
url += "&max-results=10";
// Open the request
ajaxContactRequest.open("GET", url, false);
// Send it away
ajaxContactRequest.send();
});
}
I know that there is some sort of support for queries because the listing here: Retrieving Contacts Using Query Parameters mentions that you can use the parameters found here: Contacts Query Parameters Reference which lists q=term1 term2 term 3 and `q="term1 term2 term3" are the way to do "Fulltext query on contacts data fields".
I have tried several different mixes of parameters such as first and last name as well as dates and emails. However, none of them have any impact on the results. Another thing that I am wondering is if this really matters. I'm limiting my query based on name only to try and reduce the size of the response. However, if the better practice is to just grab the whole contact set and then glean the bits of info that you need, I guess I can do that instead.
I figure you have to do multiple requests if the number of contacts is larger than the max-results size.
You need to switch to version 3 of Google Contacts API.
v1 and v2 don't have support for the "search term" (q) parameter, so you're limited to query parameters like "last updated" and "order by" and such.
So. First off they hint that all of your headers need the "GData-Version: 3.0" parameter.
https://developers.google.com/google-apps/contacts/v3/#specifying_a_version
If you're using jQuery, that's fairly straightforward. Here's an example: Set Request Header jQuery Ajax
But in the code you've got already, you can just add it to the URL for all requests.
url += "https://www.google.com/m8/feeds/contacts/default/full/?v=3";
(again in jQuery, it's easy to add it as a param too if modifying the header is scary)
The kicker, and it took me weeks to figure this out, is that the "scope" itself is wrong.
In your HTML code I'm sure you've authorized your app using...
scope="https://www.google.com/m8/feeds"
... as it says to do in the documentation. But when they say "all requests need the header" they really mean ALL requests. And if you're using Google's pre-canned HTML examples to authorize your application, then you simply don't have access to the code which would let you modify the headers. So instead you need to use...
scope="https://www.google.com/m8/feeds?v=3"
This is because the v2 API and v3 API share a scope URL, which you really only notice if you're reading the v2.0 and the v3.0 documentation side by side.
Anyway, I hope that helps.
Kieron

FireBase - how to list user-specific data?

Currently I've been looking at FireBase, and have been using the AngularJS plugin, and have found the following problem I cannot get out of.
I currently have implemented the simple login system.
Logged in with my mail and password after registering, I create a post like this:
post = {
name: "Hi",
message: "Guys",
user_id: Auth.user.id // for my current user this is 1
}
posts.$add(post)
From this point on everything is fine.
Now what I wanted to do is that in the posts/ endpoint on firebase, I want only to display the posts of the user currently logged in.
Other users may be able to read posts of others by having a public boolean variable (but that's for later)
I've been looking at the security API of Firebase (see: https://www.firebase.com/docs/security/security-rules.html)
Currently I have this:
{
"rules": {
"posts": {
"$post": {
".read": "data.child('user_id').val() == auth.id",
".write": "(data.child('user_id').val() == auth.id) || (newData.child('user_id').val() == auth.id)"
}
}
}
}
It works to a certain extend, I can write posts only if I'm logged in, but I cannot read any posts!
posts = new Firebase(base + '/posts')
posts = $firebase(posts)
The error is: FIREBASE WARNING: on() or once() for /posts failed: Error: permission_denied: Client doesn't have permission to access the desired data.
If anyone has a solution then that would be awesome!
Security rules cannot be used as data filters. You can't just read the entire posts path and expect to only retrieve the records you're allowed to see. Instead, you need to architect your data in a manner that you can read the whole path, or store an index of which records are viewable and fetch them separately.
For example, store the records by group ids or by user ids:
/posts/$group/data...
/posts/$user/data...
And then you can ensure your users have permissions by assigning them to appropriate groups, and simply fetching the messages for those groups:
var ref = new Firebase(base + '/posts/' + GROUP_ID);
var posts = $firebaseArray(ref);
Or you can create an index of messages each user/group/etc may view:
/posts/$post_id/data...
/posts_i_can_view/$user_id/$post_id/true
And fetch them individually from the master list. A tool like Firebase-util will make this much simpler:
var fb = new Firebase(base);
var ref = Firebase.util.NormalizedCollection(
fb.child('posts_i_can_view/'+USER_ID),
fb.child('posts')
)
.select('posts.message', 'posts.user_id')
.ref();
var posts = $firebaseArray(ref);
Further reading on Firebase data structures:
https://www.firebase.com/docs/web/guide/structuring-data.html
https://www.firebase.com/docs/web/guide/understanding-data.html
https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html

Error updating/posting to Twitter

I tried with this code to post on the wall (Twitter) of a user
if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
}
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
if (!auth.IsAuthorized)
{
Uri specialUri = new Uri(Request.Url.ToString());
return auth.BeginAuthorization(specialUri);
}
twitterCtx = new TwitterContext(auth);
twitterCtx.UpdateStatus("Welcome");
Probleme : the first test goes well, I posted on the wall the second test shows this error:
Error while querying Twitter.
someone can help me to solve this problem
Thanks,
LINQ to Twitter throws a TwitterQueryException when detecting an error from Twitter. You can look at the Response property of the TwitterQueryException instance to see the message that Twitter is sending back. Another way to get a complete view of the query and Twitter's response is to use Fiddler2 to view the HTTP traffic and see what Twitter's response is.
In your case, I'm looking at the fact that you said the first post worked, but the second one doesn't. This might be caused by posting a duplicate message, which Twitter doesn't allow. If you look at any of the LINQ to Twitter demos that post a message, you'll notice that they contain a DateTime, which practically guarantees that the text of each message will be different. So, In your case, you could try this:
twitterCtx.UpdateStatus("Welcome - " + DateTime.Now.ToString());
You're welcome to provide more info by posting the contents of the Response property from the TwitterQueryException. Also, for more info, I've begun a FAQ at http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation.

Resources