Error when trying to retrieve basic user information - ios

I have successfully included the Facebook Login in my IOS app however i seem to be having some difficulty getting some of the users basic information such as name, email etc....
My current code looks like this:
// Ask for the required permissions
self.loginView.readPermissions = #[#"basic_info",
#"user_location",
#"user_birthday",
#"user_likes"];
// Fetch user data
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
if (!error) {
// Display the user info
tempLabel.text = user.name;
}
}];
However there is always an error (where the if statement checks for !error, its always equal to false).
Can someone help me in trying to get this please?
Thanks,
Jake
EDIT:
2013-08-04 15:52:03.457 Ludis[37821:c07] {
"com.facebook.sdk:HTTPStatusCode" = 400;
"com.facebook.sdk:ParsedJSONResponseKey" = {
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
};
}
2013-08-04 15:52:03.458 Ludis[37821:c07] The operation couldn’t be completed. (com.facebook.sdk error 5.)

You haven't obtained the user's permission to perform the action you're attempting to perform. First call
openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:
on FBSession. Here's some more information about how to log in to Facebook from iOS

Related

iOS + Parse Cloud Code - updating a specific user (not logged in user)

I am trying to update a user (Which is not the current user). I figured that you have to use cloud code to make the update.
I have created the cloud function below to update the selected user. I am trying to add meetingId's to an array property which belongs to User class.
Cloud Code:
Parse.Cloud.define('updateUser', function(request, response) {
var userId = request.params.userId,
meetingId = request.params.meetingId;
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.addUnique("meetingsArray", meetingId)
user.save(null, {userMasterKey:true}).then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
Objective-C
//meetingId - is obtained from Meeting Object.
[PFCloud callFunctionInBackground:#"updateUser" withParameters:#{#"objectId":user.objectId, #"meetingsArray":meetingId} block:^(NSString *result, NSError *error)
{
if (!error) {
NSLog(#"%#",result);
}else if(error){
NSLog(#"%#", error);
}
}];
When I run the app - I get the following error code:
Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" UserInfo=0x1704f2780 {code=141, temporary=0, error={"code":201,"message":"missing user password"}, originalError=Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn’t be completed. (NSURLErrorDomain error -1011.)"}
I'm new to Cloud code - i just basically want to update the array that belongs to the selected user and add a meetingId to it. Any help would be greatly appreciate it.
There are a few problems with the code that will prevent it from working:
the cloud code expects the meeting id parameter to be named #"meetingId", so change the parameters passed to #{#"objectId":user.objectId, #"meetingId":meetingId}
use Parse.User, not '_User' to extend user.
get - don't build - the user being updated
Summing up...
Parse.Cloud.define('updateUser', function(request, response) {
var userId = request.params.userId;
var meetingId = request.params.meetingId;
var query = new Parse.Query(Parse.User);
query.get(userId).then(function(user) {
user.addUnique("meetingsArray", meetingId);
return user.save(null, {useMasterKey:true});
}).then(function(user) {
response.success(user);
}, function(error) {
response.error(error);
});
});
I was still getting the error after implementing #danh's answer. I needed to add
Parse.Cloud.useMasterKey()
in the .js file then everything worked perfect!

Post to the wall of an app page as the currently logged in user with iOS SDK

I hope I am using the right terminology but please for give me if I am not. I am using the iOS SDK in an iPhone app. I want to code for a user to make a post to the wall of an App page on Facebook.
Permission I get these permission
#[#"publish_actions", #"publish_pages", #"manage_pages"]
Request this is my request code
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"myAppKeyID/feed"
parameters: #{#"message": #"This is my message"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
} else {
}
}];
I get an error response
body = {
error = {
code = 200;
message = "(#200) Permissions error";
type = OAuthException;
};
};
code = 403;
In the Graph API Explorer I can do exactly the same thing with these permissions and it works fine. I see a post from me on the wall of the apps page.
Can someone please help?
I worked out the answer. The above code is fine. I was using the wrong app ID.

How to use Authentication again after it was granted prevously

-(void)getGoogleCalendar{
GTLServiceCalendar *calendarService = self.calendarService;
GTLQueryCalendar *calendarListQuery = [GTLQueryCalendar queryForCalendarListList];
[calendarService executeQuery:calendarListQuery completionHandler:^(GTLServiceTicket *ticket, GTLCalendarCalendarList * object, NSError *error) {
for (GTLCalendarCalendarListEntry *calendar in object.items) {
[self getEventsForTheGivenCalendar:calendar.identifier];
}
}];
}
For the First Time after the Login it works perfect but when app starts after that it gives error
Error Domain=com.google.GTLJSONRPCErrorDomain Code=401 "The operation
couldn’t be completed. (Login Required)" UserInfo=0x79eb4f90
{error=Login Required, GTLStructuredError=GTLErrorObject 0x79fa9270:
{message:"Login Required" code:401 data:[1]},
NSLocalizedFailureReason=(Login Required)}
I am using GTMOAuth2Authentication authentication for the login and storing the user details. If the user details are not nil it doesn't ask for login and then the error occurs while fetching the calendar.
How to fetch GTLCalendar every time the app runs?
You should set the service authorizer in order to be able to make queries.
calendarService.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:KEYCHAINITEMNAME
clientID:CLIENTID
clientSecret:CLIENTSECRET];

mailcore2 imap Error Domain=MCOErrorDomain Code=5

I in turn to the making relevant mailcore2 problems, based on past errors, and all of the share, or didn't find the solution to this problem below, so the problem I have encountered redistribution, also hope to get more help, thank you!
Mailcore2 using the code below:
self.imapSession = [[MCOIMAPSession alloc] init];
self.imapSession.hostname = hostname;
self.imapSession.port = 993;
self.imapSession.username = username;
self.imapSession.password = password;
if (oauth2Token != nil) {
self.imapSession.OAuth2Token = oauth2Token;
self.imapSession.authType = MCOAuthTypeXOAuth2;
}
self.imapSession.connectionType = MCOConnectionTypeTLS;
MasterViewController * __weak weakSelf = self;
self.imapSession.connectionLogger = ^(void * connectionID, MCOConnectionLogType type, NSData * data) {
#synchronized(weakSelf) {
if (type != MCOConnectionLogTypeSentPrivate) {
NSLog(#"event logged:%p %i withData: %#", connectionID, type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
}
};
// Reset the inbox
self.messages = nil;
self.totalNumberOfInboxMessages = -1;
self.isLoading = NO;
self.messagePreviews = [NSMutableDictionary dictionary];
[self.tableView reloadData];
NSLog(#"checking account");
self.imapCheckOp = [self.imapSession checkAccountOperation];
[self.imapCheckOp start:^(NSError *error) {
MasterViewController *strongSelf = weakSelf;
NSLog(#"finished checking account.");
if (error == nil) {
[strongSelf loadLastNMessages:NUMBER_OF_MESSAGES_TO_LOAD];
} else {
NSLog(#"error loading account: %#", error);
}
strongSelf.imapCheckOp = nil;
}];
When I use iOS8.1 equipment, error message as follows, the console output:
checking account
2015-02-15 10:58:36.712 MailCoreTest[11971:2988194] event logged:0x166a4d50 0 withData: * OK [CAPABILITY IMAP4 IMAP4rev1 IDLE XAPPLEPUSHSERVICE ID UIDPLUS AUTH=LOGIN NAMESPACE] QQMail IMAP4Server ready
2015-02-15 10:58:36.821 MailCoreTest[11971:2988194] event logged:0x166a4d50 0 withData: (null)
2015-02-15 10:58:36.824 MailCoreTest[11971:2988128] finished checking account.
2015-02-15 10:58:36.825 MailCoreTest[11971:2988128] error loading account: Error Domain=MCOErrorDomain Code=5 "Unable to authenticate with the current session's credentials." UserInfo=0x16596ec0 {NSLocalizedDescription=Unable to authenticate with the current session's credentials.}
But when I use iOS8.0 devices, console to print the results are as follows:
checking account
2015-02-15 11:22:53.249 MailCoreTest[7853:1742121] finished checking account.
2015-02-15 11:22:53.249 MailCoreTest[7853:1742121] error loading account: Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established." UserInfo=0x17e50ab0 {NSLocalizedDescription=A stable connection to the server could not be established.}
Please help me, I contact with Objective - C time is short, but I must do my best to be aggressive, still hope to give a detailed solution, sincere thank you once again, hard work!
Yes its an authentication issue, I had same issue with my app but it was working fine before.
After I got this error, I checked my gmail account and there was an email from Google with subject "Suspicious Sign in prevented" and This sign in was of CA, USA. Actually My Application was under review so it was rejected for this reason.
Then I found that gmail is disabling unauthorised IPs.
You have to enable the 2 step verification for the gmail account to resolve this and generate an app specific password. Use that password in your app and It'll work fine.
Follow below google link to generate application specific password.
https://support.google.com/mail/answer/1173270?hl=en

Fetching Current User Profile using Objective C Google Plus Client Library

I am using the Google CLient Libraries for Objective C available here..
I have successfully been able to Authorize the user and get refresh token. (Using the GTMOAuthenticaion api embedded within).
In the Selector called after successful authorization I make the Get User Profile request as follows.. (I need the id of currently loggedin/authenticated user)
-(void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error != nil) {
NSLog(#"Stop");
} else {
if ([auth canAuthorize]){
[Mediator plusService].authorizer = auth;
// Problematic Line
GTLQueryPlus *profileQuery = [GTLQueryPlus queryForPeopleGetWithUserId:#"me"]; // Notice the UserId Param
profileQuery.completionBlock = ^(GTLServiceTicket *ticket, id object, NSError *error) {
if (error == nil) {
self.mediator.gProfile = object;
} else {
NSLog(#"GPlus Service Error %#", error);
}
};
[[Mediator plusService] executeQuery:profileQuery completionHandler:
^(GTLServiceTicket *ticket, id result, NSError *error) {
if (error)
NSLog(#"Some Service Error %#", error);
}];
}
}
}
If I put "me" as parameter, I get invalid user ID error string in jSON response.
However, If I provide some userId like my own 113632923069489732066 it works perfectly fine and returns the appropriate jSON response..!!
The Example for Google Plus inside Examples folder also fails to get current user profile ending with following error.
Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Invalid user ID: {0})" UserInfo=0x7a670fa0 {NSLocalizedFailureReason=(Invalid user ID: {0}), GTLStructuredError=GTLErrorObject 0x7a67b130: {message:"Invalid user ID: {0}" code:400 data:[2]}, error=Invalid user ID: {0}}
P.S. My API Console application doesn't work with iOS option under installed app but needs be configured with "Other" option. When configured with iOS option, the oAuth fails with invalid_client error response.
My Mistake .. !! And a very silly one .. !!
I was signing in using a Gmail Account that was yet not associated with GPlus .. !! =/

Resources