How to get post id after successful FB ShareDialog post - ios

I am referring "ios 3.5 how to" by Facebook. Here is my code
[FBDialogs presentShareDialogWithParams:params
clientState:nil
handler:
^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// If there's an error show the relevant message
[self showAlert:[self checkErrorMessage:error]];
} else {
// Check if cancel info is returned and log the event
if (results[#"completionGesture"] &&
[results[#"completionGesture"] isEqualToString:#"cancel"]) {
NSLog(#"User canceled story publishing.");
} else {
// If the post went through show a success message
[self showAlert:[self checkPostId:results]];
}
}
In results I only get didComplete key with value 1. How can I get post_id?

use dictionary
call.dialogData.clientState

How about to see this dictionary call.dialogData.clientState http://developers.facebook.com/docs/reference/ios/3.5/class/FBDialogsData

Have you already checked the results NSDictionary?
Put NSLog(#"Results Dictionary: %#",results); inside your second else statement and check the content of this dictionary.

You'll only get the post_id returned if the user is logged in to Facebook on your app. That is, if the user has authenticated your app. If the user hasn't authenticated your app, this isn't returned.
So try putting say an FBLoginView, logging in, and seeing if the post_id gets returned.

I note that it only getting didComplete on ios5,if you test it on ios6,then can getting both "didComplete" and "completionGesture". It maybe a bug of facebook SDK.

Related

QBChatDelegate -chatDidReceiveMessage: getting called but dialogID is NULL

I'm utilising QB for awhile now and everything was working perfectly.
Something came up today and I'm not being able to receive QBChatMessages with a proper dialogID anymore.
I send the message with:
[self.dialog sendMessage:message completionBlock:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(#"error! %#", error);
} else {
NSLog(#"success!");
/*locally adding message to tableview*/
}
}
And the callback always results a success, the other end receives the message through:
- (void)chatDidReceiveMessage:(QBChatMessage *)message
{
NSLog(#"chatDidReceiveMessage %#", message.dialogID);
}
But the dialogID I'm getting is (null), which doesn't make any sense. The variable self.dialog.ID is not null upon sending the message, the message gets to its destination with all the text I sent, but the dialogID is (null). I verified in the Chat admin panel inside my account and the dialog does not show the new messages. I'm using v2.6.0.1 btw.
Okay, I found my problem.
Seems when I changed some sending messages methods I commented out the important part of
message.customParameters[#"save_to_history"] = #"1";
Never forget to set save_to_history custom parameter or your message will get to its recipient without a dialogID...

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.

Unable to obtain origin of NSLog in a Parse block?

I am using the following code to log in a user to my application using parse.com
[PFUser logInWithUsernameInBackground:usernameString password:passwordString
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
NSLog(#"The user has logged in");
} else {
// The login failed. Check error to see why.
}
}];
The code works great and is documented on the Parse.com API Documentation HERE
My problem however is that I want to be able to show an alert to users when their login credentials come back with with an error, currently I get the following error on my console when I try to sign in with invalid credentials: Error: invalid login credentials (Code: 101, Version: 1.2.19)
Thats great, but I have looked everywhere and cant seem to find where that code, is being created... I am looking for it so that I can add different error messages for to my users: i.e.
if ([errorString rangeOfString:#"username"].location == NSNotFound) {
//the issue is not username related
} else
{
NSLog= (#"The username has been taken");
}
Any idea how I can find the string that contains the error and examine it so that I may act accordingly to the error?
the parse error codes are all documented here:
https://parse.com/docs/ios/api/Classes/PFConstants.html
101 is kPFErrorObjectNotFound
and means 'Object doesn't exist, or has an incorrect password.'
during a login it is likely more the later ;)
so:
if(error.code == kPFErrorObjectNotFound) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"parse login error" message:#"Invalid credentials" delegate:nil cancelButtonTitle:#"ok"];
[alert show];
}
dont use the error string of an NSError as you can't really tell if it is suitable for display.
still it is likely in localizedDescription or some other userInfo field
If you look at the documentation for NSError you will see that its userInfo property is a dictionary. From your NSLog you can see that the error key contains the string you are after, so you can access it with
NSString *errorMessage=[error.userInfo objectForKey:#"error"];
Although, rather than parsing strings it is safer to check the error.code value for 101, possibly displaying the error message for more detail. Checking the error code rather than the string will ensure that a change in the string by Parse won't break your code

Error when trying to retrieve basic user information

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

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