Parse - Unity3D : How to create a user after a Facebook Connect - facebook

'm using the Facebook SDK 6.0 for Unity3D.
After my user accept the connection, I want to save his ID, email etc ... on a Parse database, and have the possibility to get some info from this database for this player (for exemple : the list of unlock levels).
How can I do it ?
I know how create an object, but I want to know, after a connection on Facebook, how to save the user and some details on Parse, without using the Parse login (as on the official Parse tutorial).
I can't understand.
Thank you very very much in advance for your help.
Best regards,
AB

You can try saving this information in the local ParseUser Object. Just add custom fields with the necessary information. For more complex solutions you can create a custom parse object to save the information.
https://parse.com/docs/unity_guide#users
var user = new ParseUser()
{
Username = "my name",
Password = "my pass",
Email = "email#example.com"
};
// other fields can be set just like with ParseObject
user["IsUnlocked"] = true;
Task signUpTask = user.SignUpAsync();
and for Facebook there is a special signup method in the ParseFacebookUtils class
https://parse.com/docs/unity_guide#fbusers
Task<ParseUser> logInTask = ParseFacebookUtils.LogInAsync(userId, accessToken, tokenExpiration);

Related

How to retrieve name of user in firebase

I am creating an app (Xcode, swift) that has a profile page for each user and I want their name to appear on that page.
I have been able to get their email address through:
let email : String = (Auth.auth().currentUser?.email)!
How would I gather the users name? I have the users UID as well.
I am using firebase by the way
If you are not using Google or Facebook to log in with firebase, You need to manually create the profile for each user. See Update a user's profile
If you're using a social provider to sign in, you can get the display name from that provider through Firebase with:
Auth.auth().currentUser?.displayName
If you're signing in with another provider, the display name won't automatically be set, and you will (as Abdullah answered) have to create your own registration system where the user enters their name - and you then store it in the displayName property of Firebase Authentication.
To achieve what you requested, you either have to use a social auth provider (such as Google or Facebook) or change it yourself from the client, as the other answers suggest.
First of all, you would have to create a changeRequest, using the following code
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
Once the change request is created, you can change whatever basic information you need to (either the photo URL or the display name) with the following code:
changeRequest?.displayName = "Lorem ipsum"
changeRequest?.photoURL = "https://your_link/path_to_image.png"
Finally, you must send the change request to Firebase, which will handle it and possibly return an error for you to handle.
changeRequest?.commitChanges { error in
if let error = error {
print(error.localizedDescription)
// You can handle the given error here
return
}
}
As others have already pointed out, you can find this and more information on the official on the official Firebase docs website.

(Xcode 6 Swift Language) saving users data (username, userEmail, userPassword) and send it to database

I'm making an IOS app for iPhone that required users to register. I want to send data to a service sites and then record it on database, but i only know how to save it locally, by using this code:
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey:"userEmail");
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey:"userPasswoed");
NSUserDefaults.standardUserDefaults().synchronize();
So the question is how can I save the users data and then send it to a service sites and record it in database (using the Swift language)?
By database, I'm guessing you mean something like parse. You can register for Parse at parse.com and go through the steps in quick start to set your app up. Parse creates a user class for you then you can create a variable for the username, email and password and send that data to parse using the pfuser class. Once you have done all of that, this is the code you can use to set those properties and send them to parse.
let user = PFUser()
user.username = username
user.email = userEmail
user.password = password

Grails Facebook Plugin - How to Handle Invalid User

I am using the wonderful Grails Facebook Plugin and things are working alright. The problem comes from the fact that I provide another way to authenticate: forms authentication. If there is already a user in the system with the email address of the Facebook user, I would like to gracefully alert the user of this fact. I don't know how to do that since I am buried inside of a service which gets called from a Filter. Ideally I would like to show an error message on the login page. Is this possible?
Inside my FacebookAuthService:
FacebookUser create(FacebookAuthToken token) {
log.info("Create domain for facebook user $token.uid")
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
String email = fbProfile.getEmail()
String emailMatch = User.findByEmailAddress(email)
if(emailMatch != null)
throw new RuntimeException("username is bad!!")
I want to display this error message to the user instead of the exception trickling all the way through. How can I do this? Thanks!
You can put this message into a flash object:
def grailsWebRequest = WebUtils.retrieveGrailsWebRequest()
def flash = grailsWebRequest.attributes.getFlashScope(request)
flash.error = "username is bad!!!"
return null // Facebook filter will skip authorization at this case
Also, instead of RuntimeException it's better to use instance of AuthenticationException. At this case you can configure Spring Security to redirect to special url after exception. Just put into Config.groovy:
grails.plugins.springsecurity.failureHandler.exceptionMappings = [
'MyException': '/usernameIsBad'
]

Access Facebook albums from a flash app

I want to create a flash Facebook application in which, after pressing a button, the user will be able to browse his/her photo albums and choose a photo. How should i do that? What will be the code under the button to gain authentication from any user using this application?
Thanks.
I am currently writing a facebook application for a university assignment that will allow the user to do everything you can do in facebook, but via the flash player window. You will need a few basic things happening in order to do it.
User log in and authentication - this must be done via Facebook - using OAuth authentication, and meeting all of facebook's security policies
register the application with facebook
Use the Graph API (facebook's developer's toolkit) to get the necessary functions that will communicate with facebook via flash.
In Flash itself you will use a bunch of URLRequest functions to send out to FB for information, then you will need to retrieve that data responses and store them to variables (extracting data with a few lines of code is easy, something like this;
//initialise variables
public var photoURL:String;
var Request:URLRequest = new URLRequest("http://www.whatever the url for the graph api service you are using which is founf from FB");
//that ^^ will send off a request for the url, you then want to use the returned data by registering an event handler like this below
functionName.addEventListener(onComplete, completeHandler);
functionName(event, EVENT)
{
var loader:URLLoader = new URLLoader(Request);
var data:XML = new XMLData(load.loader); //i think this is right but not 100% sure, fiddle with it
//then you want to extract the data that is returned, for example, extracting xml data from a rest request works by hitting data from the xml by specifying a path to the object you want. an example of xml is this <rsp stat="ok"><photos ......more code="morecode"><photo url="url of photo"></photo</photos> so you can hit the url in that example like this;
photoURL = data.photos.photo.#url; //this line will grab the photo url for you, allowing you to dynamically create an array and assign photos to the flash stage according to the url you get
}
this is fairly advanced stuff and I am assuming that you have some decent knowledge on AS3, XML, and the FB API, if you need more help just reply

Facebook status update with PHP

My requirement was to update members status from my site, i am also thinking about displaying their friends photos and their last status update.
I have looked all over the docs and cant decide which works for my need. RESTful API, JavaScript API, FQL, XFBML, FBML, FBJS ?? whcin one works best? or best way?
It should be like, when they first go to the page,there will be nothing but a login option. when they click on it, a pop up should appear and when they are authorized, we display a text area to post update. Here, i wanted to show their friends pics too
when they came back later, they should able to post right away, must not ask for login again.
Can some one help me with the code?? I dont expect you to write everything, get the friends pic and their last update into a PHP array would be nice.
Many thanks
If u need to update users data stored at ur database so u will use the facebook API to check user signed in and get his data. i have an ifram application at facebook and i am using C# code (asp.net application) and when the user request the application i authenticate that he is signed in to facebook and check if he is already exist in my database? if not so i get his information(by using facebook API) and add the user in my data base and each time he visits the application i update his information.
With respect to his friends i get all facebook ids of the user friends and then loop these IDs and get the pic of each ID.
Download Facebook Developer Toolkit that enables u communicate with facebook and use facebook API to get user information.
hope that is will help u
Visit my application in facebook and u will see these features at the following link :
http://apps.facebook.com/hanggame/
Getting the session Key :
protected void Page_Load(object sender, EventArgs e)
{
//Facebook code for integration with facebook users:
_fbService.ApplicationKey = "Application Key";
_fbService.Secret = "Secret Key";
_fbService.IsDesktopApplication = false;
string sessionKey = (string)Session["Facebook_session_key"];
if (Session["Facebook_userId"] != null)
userId = (long)Session["Facebook_userId"];
// When the user uses the Facebook login page, the redirect back here will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.uid = userId;
}
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["Facebook_session_key"] = _fbService.SessionKey;
Session["Facebook_userId"] = _fbService.uid;
Session["Facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
Response.Redirect(#"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + #"&v=1.0");
}
userId = _fbService.uid;
//End of Facebook code
}