I have to update the user password of quick blox user and the method below is not found in new version .
Please suggest me any solution.
[QBRequest updateUser:currentForgotUser successBlock:^(QBResponse *response, QBUUser *user) {
// User updated successfully
} errorBlock:^(QBResponse *response) {
// Handle error
}];
QBUpdateUserParameters *updateParameters = [QBUpdateUserParameters new];
updateParameters.website = #"www.mysite.com";
updateParameters.phone = #"8234234";
updateParameters.tags = #[#"man", #"golf"];
[QBRequest updateCurrentUser:updateParameters successBlock:^(QBResponse *response, QBUUser *user) {
// User updated successfully
} errorBlock:^(QBResponse *response) {
// Handle error
}];
https://quickblox.com/developers/SimpleSample-users-ios#Update_your_own_profile
Related
I am using Facebook sdk 3.10 to send a request to multiple friend at a time using FBWebDialogs. Following code I'm using and all thing is fine like selecting multiple friends , sending them request. But there is one problem, is this FBWebDialogs uses some limit of friends as I have more that 300 friends but this is showing only 12-15 friends always.
CODE
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Learn how to make your iOS apps social."
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"]) {
// User clicked the Cancel button
NSLog(#"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
Using above I can see only max 12 friends in the dialog? Am I missing something?
Any help would be appreciated.
You should pass the NSDictionary type object to parameters argument.
You can create like this:
NSArray *suggestedFriends = [[NSArray alloc] initWithObjects:#"fb_id1", #"fb_id2", nil];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[suggestedFriends componentsJoinedByString:#","], #"suggestions", nil];
Now
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:#"Learn how to make your iOS apps social."
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"]) {
// User clicked the Cancel button
NSLog(#"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
Here it will show all of the friends with the suggested Facebook ids.
I am building an iphone app with a rails-backed server. I am using the devise gem. I am having trouble with user logins on the client-side (everything works on the web side, and even in the terminal with CURL).
On Xcode I can create a user and I can login. After logging in
(and recieving this in the log: "User logged in!")
I am then pushed to the indexViewController- and here I receive an error that the posts don't load. The reason is because on the post_controller.rb I have a
before_filter :authenticate_user!
preventing the posts from loading. The problem is, that the auth_token which was generated upon a successful login, is not being stored and passed along to the different views. So then, in the log I get:
'You need to sign in before continuing.'
As if the first part of what I just explained never happened..
In the indexViewController viewDidLoad method I have:
if (![[APIClient sharedClient] isAuthorized]) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
[self.navigationController pushViewController:loginViewController animated:YES];
}
isAuthorized is a BOOL in the APIClient that checks if userID>0
In the user model this is the code that creates a login session
+ (void)loginUser:(NSString *)signature
email:(NSString *)email
password:(NSString *)password
block:(void (^)(User *user))block
{
NSDictionary *parameters = #{ #"user": #{
// #"signature": signature,
#"email": email,
#"password": password
}
};
[[APIClient sharedClient] postPath:#"/users/sign_in" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
User *user = [[User alloc] initWithDictionary:responseObject];
if (block) {
block(user);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
if (block) {
block(nil);
}
}];
}
I am guessing it is here that I am missing some auth_token implementation? Since it is generated automatically by devise- I am not sure how to tell xcode to remember it. The auth_token is a string that has a column in the user table on the db. Should I add auth_token as param to the dictionary that holds the user's email and username? Or how do I get the token to persist?
Any ideas would be helpful.
Not being intimately familiar with AFNetworking this is a stab in the dark, but presumably you need to set the token for subsequent requests. Assuming APIClient is a wrapper you've added around AFHTTPClient, here's a quick idea of what that might look like after reviewing the code here - AFHTTPClient.
+ (void)loginUser:(NSString *)signature
email:(NSString *)email
password:(NSString *)password
block:(void (^)(User *user))block {
NSDictionary *parameters = #{ #"user": #{ #"email": email,
#"password": password } };
[[APIClient sharedClient] postPath:#"/users/sign_in"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
User *user = [[User alloc] initWithDictionary:responseObject];
// retrieve and save auth token
NSString *token = [responseObject objectForKey:#"authToken"];
[[APIClient sharedClient] setAuthorizationHeaderWithToken:token];
if (block) {
block(user);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
if (block) {
block(nil);
}
}];
}
I am using Google Plus integration where I have to fetch circles of user.
I am passing the Url:https://www.googleapis.com/plus/v1/people/Your_User_Id/people/visible?key=APP_Key.
I am getting the response as:
{ error = { code = 403; errors = ( { domain = global; message = Forbidden; reason = forbidden; } ); message = Forbidden; }; }
What kind of permission do I need for This request?
You can only do this for the signed in user - so the "Your_User_Id" should always be "me". It's fine to pass the app key as well, but you must be making the call with an oAuth 2.0 token from a user who has signed in to your app. You can see all the details here: https://developers.google.com/+/mobile/ios/people#retrieve_a_collection_of_people
Basically you'd need to implement sign-in, if you haven't already, then you can use the plusService in the GPPSignIn sharedInstance:
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:#"me"
collection:kGTLPlusCollectionVisible];
[[[GPPSignIn sharedInstance] plusService] executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
GTMLoggerError(#"Error: %#", error);
} else {
// Get an array of people from GTLPlusPeopleFeed
NSArray* peopleList = [peopleFeed.items retain];
}
}];
That is calling the URL that you're giving there.
I am trying to check if user has already granted publish permission or not. if he has not granted permissions before then i navigate him to permissions screen via: requestNewPublishPermissions
-(void)checkPermissions
{
// Get the most recent status
[FBRequestConnection
startWithGraphPath:#"me/permissions"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
//This Condition Never Executed
if([[result objectForKey:#"data"] objectForKey:#"publish_actions"])
{
//permissions exist
}
else
{
[self openSessionForPublishPermissions];
}
NSString *permission = [[result objectForKey:#"data"] objectForKey:#"publish_actions"];
NSLog(#"permissions data = %#",data);
}
else
{
NSLog(#"error"); //Control goes to this block
}
}];
}
In code above if(!error) block is never executed and it always returns Error
Where i'm going wrong? Am i missing something?
You can see permissions in the active session. Here is how it's done in the HelloFacebookSample :
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// permission does not exist
} else {
// permission exists
}
Instead of manually checking the permissions, you could check if the session is active and request publish permissions: if the user has already granted the permissions, an additional confirmation dialog will not be posted. See the code sample below:
- (void)requestWritePermission:(UIViewController *)viewController channel:(NSString *)channel callback:(void(^)(BOOL success))callback
{
if ([FBSession.activeSession isOpen])
{
[FBSession.activeSession requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
callback(error == nil);
}];
}
else
{
// Attempt to request publish permission without read permission.
}
}
The code is not complete, but should get you started.
I have a Facebook SSO working perfectly on my app, using last release of Facebook Objective-C SDK.
I need to ask an extra permission inside the app if user do "something". I don't need to ask that permission if user gave it to me before, so, I guess, in Facebook SDK there should be a method
-(BOOL) checkPermission:(NSString*) permission;
so I can use it like this:
if( [facebook checkPermission:#"email"] ) {
Is there a way to do this?
This question is a bit old but you can now check what permissions the active session has without making a graph request. Here is how it's done in the HelloFacebookSample :
if ([FBSession.activeSession.permissions indexOfObject:#"publish_actions"] == NSNotFound) {
// permission does not exist
} else {
// permission exists
}
Just replace "publish_actions" with "email".
SDK not providing direct method for checking specific permissions but you can check if user granted permission to your application by checking permissions connection of user object in Graph API
GET https://graph.facebook.com/me/permissions
Same can be achieved with FQL query on permissions table
SELECT email FROM permissions WHERE uid = me()
IMPORTANT: This seems to be true for an older version of the Facebook SDK (for example 3.9.0). In 3.15.0 it doesn't work this way anymore. You should use [session.permissions] as Raphaƫl Agneau says in his answer.
You have to use the following method, because [FBSession activeSession].permissions seems to return the permissions you requested, not the real ones.
[FBRequestConnection startWithGraphPath:#"/me/permissions"
completionHandler:^(FBRequestConnection *c, id result, NSError *error) {
if (!error) {
NSDictionary *permissions= [(NSArray *)[result data] objectAtIndex:0];
if (![permissions objectForKey:#"publish_actions"]) {
// Ok, continue with your logic
} else {
// Permission not found, maybe request it (see below)
}
} else {
// Treat error
}
}];
See here for more info:
https://developers.facebook.com/docs/facebook-login/ios/v2.0#permissions-checking
If the permission is not found you may want to request it this way:
[session requestNewPublishPermissions:PERMISSIONS_YOU_WANT
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession* session, NSError* error) {
// Try again the /me/permissions above
}];
Here's my code for FBSDK 4.2.0 for checking permissions. The string that's passed in is the name of the permission, e.g. "publish_actions"
- (void) checkForPermission:(NSString *)permission granted:(void (^)(void))sBlock denied:(void (^)(void))fBlock {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"me/permissions" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
BOOL hasPermission = NO;
if (!error) {
NSArray *permissions = [result objectForKey:#"data"];
for (NSDictionary *dict in permissions) {
if ([[dict objectForKey:#"permission"] isEqualToString:permission]) {
if ([[dict objectForKey:#"status"] isEqualToString:#"granted"]) {
hasPermission = YES;
}
}
}
}
if (hasPermission) {
(sBlock) ? sBlock() : sBlock;
} else {
(fBlock) ? fBlock() : fBlock;
}
}];
} else {
(fBlock) ? fBlock() : fBlock;
}
}
For the SDK 4+ you have these 2 ways of getting the permissions:
[[FBSDKAccessToken currentAccessToken] hasGranted:#"user_photos"]
or
[[[FBSDKAccessToken currentAccessToken] permissions] containsObject:#"user_photos"]