I am implementing spring-social-facebook 2.0.3.RELEASE, however I would like to know how to retrieve the access token expiry time?
Below is the code to access facebook to fetch user profile, but how to retrieve the access token expiry time?
Facebook facebook = new FacebookTemplate(accessToken);
String[] fields = { "id", "email", "first_name", "last_name" };
User userProfile = facebook.fetchObject("me", User.class, fields);
Related
I am creating a Memer social media app. So in this everything is ready but I am confused in providing Unique display name for all users. User name are given by users. But how to validate that it is really present or not? All data are stored in firebase cloud firestore. So can anybody can help me?
Username is stored is like this: collection "users" -> document "userId" ->field "username"
For this I made a new collection with the name username. And before creating the account i was calling this function to check availability:-
checkUsernameIsUnique(String username)async
{
QuerySnapshot querySnapshot;
setState(() {
loading=true;
});
querySnapshot=await FirebaseFirestore.instance.collection('username').where("username",isEqualTo: username).getDocuments();
print(querySnapshot.documents.isNotEmpty);
return querySnapshot.documents.isEmpty;
}
checkUsernameIsUnique('username to be checked').then((val){
if(val)
{
//create the user and store the username in username collection also
FirebaseFirestore.instance.collection('username').document(widget.username).setData({
"username":widget.username,
});
}
else
//username is taken
});
u can create cloud function which will get username and returns bool if its unique or not.
I'm currently trying to figure out a way for my MEAN stack application to keep track of which users have paid to grant them access to a certain portion of my webpage. I've considered several options: Stripe customer ID, MongoDB record, And HTML attribute I can update.
My mean stack keeps track of users by JWT, and it appears stripe assigns them their own customer ID which isn't ideal. Can it done with JWT as opposed to their forced cutomer ID?
MongoDB record. Which is what I'm thinking might be the best option. When a new user has been created, i'll give it an attribute of hasPaid = no. Then update the record of that customer when a payment is submitted. Then I guess run a script to set everyone back to unpaid each day?
HTML element/attribute. I don't know if this is even possible; but it would be cool to create a key that is carried during the HTML session after payment is received. If the person closers the browser then the session would be closed?
I'm looking for guidance on my 3 options to determine if they're the best solution. Also, if anyone has any suggestions as to alternatives, I'm all ears!
Thanks in advance.
Speaking generally, the most common approach would be the second one: use an attribute in your data model that indicates whether the user has paid/should be granted access. When a charge is created [0] successfully, update the model to indicate so, then filter access based on this attribute.
[0] https://stripe.com/docs/api/node#create_charge
Use a Boolean value in your user model.
var UserSchema = new Schema({
name: String,
hasPaid: {type: Boolean, default: false} //set this false
});
then in your REST API routes, the user buys the product; now set hasPaid to true
// req.user._id is passport config
User.findOneAndUpdate({_id: req.user._id}, {$set: {"hasPaid":istrue}}).exec(function(err) {
if(err) {
throw err;
}else {
req.flash('success', 'Thank you for submitting the form.');
res.render('charge', {
layout: 'dash',
user: req.user,
success: req.flash('success')
});
}
});
Now you can keep track of the users that purchased your products to grant them access to other parts of your site.
Stripe.js comes with Checkout.js which makes it even easier to use Stripe's service.
Copy and paste this into your html/jade/handlebars or view file. This will display a popup form to let the user type in his or her cc information.
<form action="/charge" method="POST">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_bla3hf&kc033"
data-image="/square-image.png"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-amount="2000">
</script>
</form>
You will receive a token once the user presses submit that you grab on your server. From inside your REST API route, you can charge the customer:
var token = req.body.stripeToken; // Using Express
// Create a charge: this will charge the user's card
var charge = stripe.charges.create({
amount: 1999, // Amount in cents
currency: "usd",
source: token,
metadata: {
user: req.user._id,
email: req.user.local.email
}
description: "Example charge" //keep track by writing a description or you can use the metadata property Stripe has to offer in the charges object
},function(err, charge) {
if (err && err.type === 'StripeCardError') {
// The card has been declined
}else {
res.redirect('/thanks-for-your-order');
console.log('charge here ' + charge.id); //store the id
console.log('charge here ' + charge.invoice); //store the invoice
console.log('charge here ' + charge.customer); //store the customer id
}
});
You can now track each order by storing the properties of the charge object in any model you wish.
I can easily get the user id from model.get("session.userId"); I am having trouble finding out how to use this to get the user's email.
If you have a Users collection, you can use the userId to get the user object which would have the user's email.
// in the controller
var userId = model.get('session.userId');
userEmail = model.get('users.' + userId + '.email');
// in the view
<div>#root.users[userId].email</div>
Hope that is helpful :)
I want to get the members id of private facebook groups using facebook api and c#. i can get users id of open facebook group please any idea.
var fb = new FacebookClient(AccessToken);
//var query = string.Format("select name from group where gid = {0}", name);
var query = string.Format("select uid from group_member where gid = {0}", gid);
//dynamic rest = fb.Get("167899503240064/members");
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic result = fb.Get("/fql", parameters);
// JObject GroupListJson = JObject.Parse(result.ToString());
var r1 = (from i in (IEnumerable<dynamic>)result.data
select new
{
i.id
});
Permissions
To read the group_member table you need:
any valid access_token if the group is public (i.e. the group's privacy setting is OPEN)
user_groups permission for a user's non-public groups or to see the bookmark_order
or unread fields for a user's groups
friends_groups permission for a
user's friend's non-public groups
Previous to the query, you need to request the user_groups permission.
To get this working, please start from here: How to use user permissions with Facebook C# SDK
I've seen many fanpages getting my friendlist after I like their page, without any permission dialog screen, I've tried alot to do it but always got "exception token required".
So is it possible to get users friends list after they like our page??
Thanks
Note, I am using underscore.js (http://documentcloud.github.com/underscore/) with no conflict:
var UnderScore = _.noConflict();
This query gets friends for me(), which is currently logged in Facebook user. You can replace me() with a Facebook user id.
Code to get friends:
var friends = {handles:[],ids:[],names:[]};
var q = 'select username, uid, name from user where '+
'uid IN (SELECT uid2 FROM friend WHERE uid1 = me())';
var r=FB.Data.query(q);
r.wait(function(rows){
if (UnderScore.isArray(rows) && (rows.length>0)) {
UnderScore.each(rows,function(i){
if (i.username && !UnderScore.isNull(i.username)) {
friends.handles.push(i.username.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.username.toString().toLowerCase()] = i.name
}
}
if (i.uid && !UnderScore.isNull(i.uid)) {
friends.ids.push(i.uid.toString().toLowerCase());
if (i.name && !UnderScore.isNull(i.name)) {
friends.names[i.uid.toString().toLowerCase()] = i.name
}
}
});
}
}
After that code runs, which will be an asynchronous event, the variable friends will be populated with ids, names, and handles for Facebook friends.
No this is not possible. You need the current user id with sufficient permissions to get the user's friends' list, and Facebook won't share the user's id just by him liking your page.
I'm not sure how these pages you are talking about are doing it, maybe using the old deprecated FBML, but again...I don't think this is possible without user authorization.