I am new in IOS development?
In my project I want to invite Facebook friend.when Facebook app is installed and not installed in both cases i want to invite my friend?
how can be done
//Below is my code
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just smashed friends! Can you beat it?"]
title:#"StopNSwap"
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Case A: Error launching the dialog or sending request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// Case B: User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
NSLog(#"Request Sent.");
}
}}
friendCache:nil];
As far as I understand you are trying to send an app-to-user request to invite user's Facebook friends to start using your application, correct? Checkout the first answer here, Paul suggests an effective way of doing it using the Facebook SDK : How to send add friend request (to facebook user) from iOS application?
Related
My website (Spring MVC) allows users to sign up by using their Facebook accounts and sign into my site later with their Facebook accounts. I use scribejava (version 6.6.3) (https://github.com/scribejava/scribejava) for the Oauth integration with Facebook.
I have tested a use case and am unable to find a way to resolve it. Here is the list of steps:
The tester goes to my site's "Log in" page, clicks "Log in with Facebook", grants permissions at Facebook, gets redirected to my site, and signs out. This is a normal and successful flow.
The tester sign into Facebook at Facebook.com
The tester goes to Settings->Apps and Websites and removes my site
The tester goes to my site's "Log in" page, clicks "Log in with Facebook" button, gets redirected to Facebook, and sees an error message.
At step 4, the tester always gets an error message at the Facebook site instead of asking the tester to grant permissions again. See the following screenshot:
I cannot find a way at Facebook to remove this message when clicking on the "Log in with Facebook" button. Here is my code for the web interface. Did I miss something?
#RequestMapping( value="/facebook", method = RequestMethod.GET)
public void facebook(HttpServletRequest request,
#RequestParam(value = "page", required = true) String page,
HttpServletResponse response) throws Exception {
try {
OAuth20Service service = new ServiceBuilder(config.getProperty("facebook.clientId"))
.apiSecret(config.getProperty("facebook.clientSecret"))
.callback(getCallback())
.build(FacebookApi.instance());
String authUrl = service.getAuthorizationUrl();
response.sendRedirect(authUrl);
} catch (Exception e) {
response.sendRedirect("/oauthFail");
}
}
#RequestMapping( value="/facebook/callback", method = RequestMethod.GET)
public void facebookCallback(HttpServletRequest servletRequest,
#RequestParam(value = "code", required = false) String code,
#RequestParam(value = "error", required = false) String error,
HttpServletResponse servletResponse
) throws Exception {
try {
OAuth20Service service = new ServiceBuilder(config.getProperty("facebook.clientId"))
.apiSecret(config.getProperty("facebook.clientSecret"))
.callback(getCallback())
.build(FacebookApi.instance());
OAuth2AccessToken accessToken = service.getAccessToken(code);
final OAuthRequest request = new OAuthRequest(Verb.GET, "https://graph.facebook.com/v3.2/me");
service.signRequest(accessToken, request);
final com.github.scribejava.core.model.Response response = service.execute(request);
String body = response.getBody();
JSONObject jObject = new JSONObject(body);
String email = jObject.getString("email");
//success. use the email to create an account or if the email address exists, direct a userto their account page
} catch (Exception e) {
response.sendRedirect("/oauthFail");
}
}
How to handle this situation? I feel either something is wrong is my code or scribejava has a framework issue. Or this is a Facebook specific issue?
I have just tested the case. Couldn't reproduce.
Did you try running this Example
https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/FacebookExample.java
?
I think your problem can be with API versions logic in Facebook.
You can try to explicitly use the latest one .build(FacebookApi.customVersion("3.2"))
I am working on a Flutter app and need to include the Facebook and Google login options in our app login page. I am not using Firebase and working on the MySQL database for storing and retrieving user's data.
I am looking for Adding the FB and Google authentication in my flutter app without the Firebase. I was not able to find any article for this. Everywhere it is always using the Firebase.
After following a tutorial, I have registered my app in FB Developer console, but I am not sure what will be put in the 'OAuth redirect URL' field there.
Currently, I am using xampp server and nodeJS for server side handling. Below is the code which I am calling on my button click. I am using plugin for Facebook authentication(Please let me know if this plugin is specifically for Firebase).
void initiateFacebookLogin() async {
var facebookLogin = FacebookLogin();
facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;
print("Inside fb login");
var facebookLoginResult = await facebookLogin
.logInWithReadPermissions(['email', 'public_profile']);
switch (facebookLoginResult.status) {
case FacebookLoginStatus.error:
print("Error");
onLoginStatusChanged(false);
break;
case FacebookLoginStatus.cancelledByUser:
print("CancelledByUser");
onLoginStatusChanged(false);
break;
case FacebookLoginStatus.loggedIn:
print("LoggedIn");
var graphResponse = await http.get(
'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email,picture.height(200)&access_token=${facebookLoginResult.accessToken.token}');
var profile = json.decode(graphResponse.body);
print(profile.toString());
onLoginStatusChanged(true, profileData: profile);
break;
}
}
As mentioned in the comments, both Facebook and Google Sign in can work without Firebase. There's a sample code for Flutter google_sign_in package that you can try here.
I am using the Facebook C# SDK (.NET 3.5) and I am trying to make a basic, server side user to user request from within my app. For example, I have a game and players can challenge other players. After a player goes through the FB auth process, they can pick a Facebook friend to play against, play their game, and once the game ends, I want to send a server side FB challenge request from the player that initiated the challenge (challenger) to the player that was challenged (the challengee). The error and my code is below. The only people that can be challenged are those players that have already authorized the app so it's not an auth issue.
Error Message
(OAuthException - #2) (#2) Failed to create any app request.
Code/Method for Sending The Request
private void sendFbChallengeRequest(int challengeeId)
{
var app = new FacebookClient(Session["AccessToken"].ToString());
var parameters = new Dictionary<string, object>();
parameters["message"] = "I have challenged you to a game!";
parameters["title"] = "I challenged you!";
parameters["to"] = challengeeId;
var result = (IDictionary<string, object>)app.Post("/" + challengeeId + "/apprequests", parameters);
}
The error is happening on the last link of the method: var result = (IDictionary)app.Post("/" + challengeeId + "/apprequests", parameters);
Any help on this would be appreciated. Tx in advance!
I have a problem with getting the information if the user is a fan of a page (fanpage) becouse sometimes this query
SELECT uid FROM page_fan WHERE uid=$mUserId AND page_id=$iPageId
gets me an empty result although the user is a fan of the page
I used this JavaScript method which returned me "resp.error_code" and "resp.error_msg" was "Invalid API key"
FB.api({
method: 'pages.isFan',
page_id: 'FB_FAN_PAGE_ID',
uid: $iUser
}, function (resp) {
if (resp == true) {
alert('fan');
} else if (resp.error_code) {
alert(resp.error_msg);
} else {
alert('no-fan');
}
});
but the code is correct as the application starts and what is strange it sometimes works and sometimes doesn't work.
I try to get the user is fan form request just like in this post How to check if a user likes my Facebook Page or URL using Facebook's API but it doesn't work.
Help pleace
With JS SDK you can check if the currently logged-in user has liked a page like this:
FB.api("me/likes/" + appPageId, function(response) {
if(response && response.data[0]) {
//user has liked the page
} else {
//user has not like the page
}
});
i'm attempting to provide a facility on my site that allows a user to create a facebook event for their booking.
http://developers.facebook.com/docs/reference/api/event/
now im doing the correct process:
1) first getting authorisation from the user
https://graph.facebook.com/oauth/authorize?client_id=APP_ID&redirect_uri=http://urlimredirectingto.comtype=web_server
2) requesting for an access token with the "code" that is returned in step 1
https://graph.facebook.com/oauth/access_token
3) using the access_token to create the event ...
string facebookCreateUri = string.Format("https://graph.facebook.com/{0}/events", loggedInMember.FacebookUID);
var formData = new HttpUrlEncodedForm()
{
{"access_token", accessToken},
{"owner", loggedInMember.FacebookUID},
{"description", "nice event that should be on the owners wall"},
{"name", "event on the users wall"},
{"start_time", "1272718027"},
{"end_time", "1272718027"},
{"location", "rochester"},
{"privacy","OPEN"}
};
HttpContent content = HttpContent.Create(formData);
HttpClient client = new HttpClient();
var response = client.Post(facebookCreateUri, "application/x-www-form-urlencoded", content);
but the event is posted on my app's wall, not the user's wall. It shouldn't have anything to do with the authentication/access_token elements because i use the same process to post on the user's wall. (http://developers.facebook.com/docs/reference/api/status/) and that works just fine.
I came back with a solution, after a week of working at many features with Facebook SDK, it finally works!
protected void onPostEvent(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = new FacebookWebClient(CanvasAuthorizer.FacebookWebRequest);
dynamic parameters = new ExpandoObject();
parameters.description = txtEvDett.Text;
parameters.name = txtEvName.Text;
parameters.start_time = DateTime.Now.ToString("yyyyMMdd");
parameters.end_time = DateTime.Now.AddDays(1).ToString("yyyyMMdd");
parameters.access_token = CanvasAuthorizer.FacebookWebRequest.AccessToken;
dynamic eventDet = fb.Post("me/events", parameters);
litEvent.Text = String.Format("You have created the event with ID: {0}", eventDet.id);
lnkEvent.Visible = true;
lnkEvent.NavigateUrl = String.Format("http://www.facebook.com/event.php?eid={0}", eventDet.id);
}
}
For events, you have to request the create_event permission.
You should use /me/events to post on your events.
I user the C# SDK for Facebook from Codeplex - last version available for dld (aug 2011 - v5.2.1).
Good luck!
I don;t see in your request for Authorization any permission.. base permissions are not enough to do the postings.
i used:
https://www.facebook.com/dialog/permissions.request?app_id=MY_APP_ID&next=MY_APP_URL&display=page&response_type=code&canvas=1&perms=publish_stream,user_about_me,email
This is in the context of a canvas app. where MY_APP_URL is the url from facebook of the app:
http://apps.facebook.com/MY_APP_NAME_OR_ID
See extended permissions for events and check event's page in documentation
[EDIT] - I came back, sorry, now i did a test, and indeed, it works for me, but only of i post on my app's wall; even if i provided the 'user_events' permission i get this error:
The remote server returned an error: (403) Forbidden when posting on a user's wall.
This being said, i also subscribe to this question.