I successfully integrate the face-book API and able to get all user profile but the problem is the value i am getting without permission dialog. In place of permission dialog i am getting blank white dialog without any content or any buttons.I am using FBConnect.
I Done with this code i stuck from last many days because i am not able to find the reason also i tried google to get solution but not get success.
My code is here to display dialog.
`-(void)askPermission:(id)target{
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init]
autorelease];
//dialog.permission = [NSString stringWithString: #"user_birthday,user_interests"];
dialog.delegate = self;
dialog.permission = #"user_interests,user_birthday";
[dialog show];
}`
in FBPermissionDialog.m
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
// if (_permission = [NSString stringWithFormat:#"user_interests"]);
// {
// NSURL* url = request.URL;
// if ([url.scheme isEqualToString:#"fbconnect"]) {
// if ([url.resourceSpecifier isEqualToString:#"success"]) {
// [self redirectToLogin];
// return NO;
// }
//}
return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
-(void)dialogDidSucceed:(FBDialog*)dialog {
NSString* fql = [NSString stringWithFormat:
#"select name, first_name, last_name, hometown_location, sex, pic_square, current_location, interests, birthday_date , activities, tv, movies, music, books from user where uid == %lld", _session.uid];
NSLog(#"%#",fql);
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
NSLog(#"%#",params);
[[FBRequest requestWithDelegate:self] call:#"facebook.fql.query" params:params];
}
Please help me i don't know why i didn't get the permission Dialog and getting blank screen .Any help will be appreciated.
Thank You
meaning you are not getting the login credential dialogue. Is there any dialog appearing BUT its blank? If yes please make sure you have the latest Facebook for IOS sdk downloaded please :) Link : https://github.com/facebook/facebook-ios-sdk
Related
I am implementing the Facebook SDK into my app . I am using FBLoginView to login with Facebook. I have a UIButton, which I'm using to share on a user's Facebook wall. Now I don't want to login using FBLoginView , i want to check if there is a Facebook app, and if the user has logged in.
- (IBAction)pickFriendsList:(UIButton *)sender
{
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *sender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString* fid;
NSString* fbUserName;
for (id<FBGraphUser> user in friendPickerController.selection)
{
NSLog(#"\nuser=%#\n", user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"test", #"message", #"http://webecoist.momtastic.com/wp-content/uploads/2009/01/nature-wonders.jpg", #"picture", #"Sample App", #"name",fid,#"tags",fid,#"to",#"106377336067638",#"place", nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed",fid] parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
//Tell the user that it worked.
}
}
}];
}];
}
}];
}
I am assuming that you are using iOS 6 sdk. In which case, Use below code (workable for device) :
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
//user is already logged in using iOS integrated FB a/c
}
else
{
//user is not logged in
}
Note: FBSession can't check this criteria. So session check with FBSession has a different meaning from above code.
Regards,
Check for the URL Scheme fb://
[[UIApplication sharedApplication] canOpenURL:#"fb://"] returns YES if Facebook App is installed. This post lists, de available URL schemes for Facebook: https://stackoverflow.com/a/5707825/1511668
Maybe fb://online is what you are looking for.
I want to post some text to a users wall using the facebook sdk in an iOS app.
Is posting an open graph story now the only way to do that?
I've found with open graph stories they are really strange, you can only post things in the format "user x a y" where you preset x and y directly on facebook, like user ata a pizza or user played a game. Setting up each one is pretty laborious too because you have to create a .php object on an external server for each one.
Am I missing something or is there a simpler way to go about this?
Figured it out by browsing the facebook tutorials a bit more.
-(void) postWithText: (NSString*) message
ImageName: (NSString*) image
URL: (NSString*) url
Caption: (NSString*) caption
Name: (NSString*) name
andDescription: (NSString*) description
{
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
url, #"link",
name, #"name",
caption, #"caption",
description, #"description",
message, #"message",
UIImagePNGRepresentation([UIImage imageNamed: image]), #"picture",
nil];
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:#"publish_actions"]
defaultAudience: FBSessionDefaultAudienceFriends
completionHandler: ^(FBSession *session, NSError *error)
{
if (!error)
{
// If permissions granted and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}];
}
else
{
// If permissions present and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}
-(void) postToWall: (NSMutableDictionary*) params
{
m_postingInProgress = YES; //for not allowing multiple hits
[FBRequestConnection startWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
m_postingInProgress = NO;
}];
}
the easiest way of sharing something from your iOS app is using the UIActivityViewController class, here you can find the documentation of the class and here a good example of use. It is as simple as:
NSString *textToShare = #”I just shared this from my App”;
UIImage *imageToShare = [UIImage imageNamed:#"Image.png"];
NSURL *urlToShare = [NSURL URLWithString:#"http://www.bronron.com"];
NSArray *activityItems = #[textToShare, imageToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
This will only work on iOS 6 and it makes use of the Facebook account configured in the user settings, and the Facebook SDK is not needed.
You can use Graph API as well.
After all the basic steps to create facebook app with iOS, you can start to enjoy the functionality of Graph API. The code below will post "hello world!" on your wall:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
...
//to get the permission
//https://developers.facebook.com/docs/facebook-login/ios/permissions
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
NSLog(#"publish_actions is already granted.");
} else {
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
//TODO: process error or result.
}];
}
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/feed"
parameters: #{ #"message" : #"hello world!"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"Post id:%#", result[#"id"]);
}
}];
}
...
The basic staff is presented here: https://developers.facebook.com/docs/ios/graph
The explorer to play around is here:
https://developers.facebook.com/tools/explorer
A good intro about it: https://www.youtube.com/watch?v=WteK95AppF4
I am doing facebook integration part in my project. I downloaded facebook integration sample project from rey wenderlich and then changed appkey and appsecretkey. When I run this app, login validation is working fine and then it shows error.this comes in the same popup after login .
Error: This endpoint has been deprecated. To temporarily reenable it,you may disable the “august_2012” platform migration.I will be permanently disabled on August 1 ,2012
How to fix this error
The functionality I am using is the same of the FbConnect sample code
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
self.usersession =session;
NSLog(#"User with id %lld logged in.", uid);
[self getFacebookName];
}
- (void)getFacebookName {
NSString* fql = [NSString stringWithFormat:
#"select uid,name from user where uid == %lld", self.usersession.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
[[FBRequest requestWithDelegate:self] call:#"facebook.fql.query" params:params];
self.post=YES;
}
This has a nice documentation with examples
I have integrated facebook connect into my Xcode 4 project for an iPhone. Here is the code for iPhone FBconnec. FBconnect.h and FBSession.h already included.
- (void)viewDidLoad{ _session = [[FBSession sessionForApplication:#"APPKey"
secret:#"APPSecret"
delegate:self]retain];
FBLoginButton* fbButton = [[[FBLoginButton alloc] init] autorelease];
fbButton.frame = CGRectMake(228, 50, 85, 50);
[self.view addSubview:fbButton]; }
The code is working fine, but for some facebook accounts when run the FQL query to select email from user. I get NULL as shown below
length of users Array: (
{
"contact_email" = "<null>";
email = "<null>";
"first_name" = Ali;
"last_name" = Subhani;
uid = 696377693;
}
How can I get the extended permission. I am just using following code to run the query. Which contains word params, I think it has to do something with FBRequest. Have a look at the code below
- (void)getFacebookName {
//==================== MAKING FACEBOOK REQUEST =============================
NSString* fql = [NSString stringWithFormat:
#"select uid,first_name,last_name,email from user where uid == %lld",
self._session.uid];
NSDictionary* params =
[NSDictionary dictionaryWithObject:fql
forKey:#"query"];
[[FBRequest requestWithDelegate:self]
call:#"facebook.fql.query" params:params];}
Where should I enter extended permissions so I can get user email.
Thanks.
I use
[appDelegate.facebook authorize:
[NSArray arrayWithObjects:
#"offline_access", #"email", #"user_checkins", #"publish_checkins", nil]
delegate:delegate
localAppId:localAppId];
...to authorize and request email access (using the #"email" permissions key above). I'm not sure if a user can have NO email address, as they have at least one to login with.
However, Facebook gives the user the option to obfuscate it from you with an arbitrary #facebook.com account that forwards to their regular email account.
I am new to iphone development, i want to display the permission page after logging facebook.
buttonIndex is the index of my actionsheets.
if(buttonIndex == 1)
{
session = [FBSession sessionForApplication:#"My App key" secret:#"My Key" delegate:self];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
}
by using those code successfully loggin to facebook, but i want to permission page to display,
so i can use,
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
NSLog(#"User with id %lld logged in.", uid);
FBPermissionDialog* dialog1 = [[[FBPermissionDialog alloc] init] autorelease];
dialog1.delegate = self;
dialog1.permission = #"uid";
[dialog1 show];
}
But its not working. Where can i put that code.
And I want to share my content after the permission allowed.
If i logout the facebook, it goes to the browser but i want to return my application after logout,
Please help me out, guide me plz.
I would change this dialog1.permission = #"uid"; to something like this
dialog1.permission = #"publish_stream";. Because you want to publish your content to the users stream, right?
- (void)session:(FBSession*)session didLogin:(FBUID)uid
After loggin in I would first check if you might already have the permission to publish to the user's stream, by creating a FBRequest
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: #"publish_stream", #"ext_perm", nil];
[[FBRequest requestWithDelegate:self] call:#"facebook.users.hasAppPermission" params:params];
The result you can evaluate here
- (void)request:(FBRequest*)request didLoad:(id)result
e.g. like this
if ([request.method isEqualToString:#"facebook.users.hasAppPermission"])
{
NSString *success = result;
if ([success isEqualToString:#"1"])
{
NSLog(#"User has app permission");
// publish content now
...
}
else
{ // else ask for permission, opening permission dialog
...
}
I highly recommend this guy's tutorial, Brandon Treb, on integrating Facebook. He does a very thorough presentation and takes you line-by-line, so if it does not work, its a typo on your part. His tutorial got me up and running in less than two hours.
http://brandontreb.com/