How to get token_for_business for Facebook login - iOS - ios

How can I get token_for_business from Facebook login? I have setup a business and associated my application with that business. Facebook documentation says you need to call GET /me?fields=token_for_business on User node, and it will return following json.
{
"id": "1234567890"
"token_for_business": "weg23ro87gfewblwjef"
}
I tried by providing token_for_business in parameter list of /me call but didn't work. Need advises.
Edit
I found this URL https://developers.facebook.com/docs/graph-api/reference/v2.5/user and tried by passing token_for_business in param of initWithGraphPath but no gain. I checked in Graph API Explorer and getting the required data. But not sure how to call from my objective-C code.
Edit 2
I Inspected the error object of initWithGraphPath:#"me?fields=token_for_business" call and found following details
Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=403, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=(#200) Application must be associated with a business. https://business.facebook.com/, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=200, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 200;
"fbtrace_id" = "EN9bN/YMloA";
message = "(#200) Application must be associated with a business. https://business.facebook.com/";
type = OAuthException;
};
};
code = 403;
}}
But if I try my app in Graph API Explorer then I'm getting the required data. So now it confusing me.

Related

SQRDReaderSDK.shared.authorize() doesn't have callback initially

I currently am unable to authorize the SquareReaserSDK with iOS (Swift).
I have a node instance that takes in an access_token.
I then call listLocations()
I provide the first location_id in the body of a CreateMobileAuthorizationCodeRequest()
I then pass the resulting mobile auth code to the client
After successfully retrieving a mobile auth token and providing that to the below, the first time this is called there is no callback. The block if statement never fires.
Redundant calls results in an authorization_already_in_progress error (the if statement is fired).
SQRDReaderSDK.shared.authorize(withCode: mobileAuthToken) { location, error in
if let authError = error {
print("Authorize SquareReaderSDK", authError.localizedDescription)
} else {
print("Authorize SquareReaderSDK", location)
Defaults[.establishment]?.squareMobileAuthToken = mobileAuthToken as! String
}
}
authorize() endpoint reference: https://developer.squareup.com/docs/api/reader/ios/Classes/SQRDReaderSDK.html#/Authorization
Redundant calls results in:
vvvvv SQUARE ERROR vvvvv
ERROR: Something went wrong. Please contact the developer of this application and provide them with this error code: authorization_already_in_progress
DEBUG CODE: authorization_already_in_progress
DEBUG MESSAGE: Authorization is already in progress. Please wait for SQRDReaderSDK.shared.authorize() to complete.
^^^^^ SQUARE ERROR ^^^^^
At any point while trying to authorize the device, I get the following error when trying to present the checkoutController:
Checkout Failed:
This device is not currently authorized to accept payments with Square.

Sharing to specific Facebook page using Swift SDK GraphSharer

In my iOS app I'm trying to use the Facebook Swift SDK so that a user can post a URL to a specific Facebook page that they manage.
I've managed to get the following code working - but it only shares the post to my home timeline:
let content = LinkShareContent(url: URL(string: urlString)!)
let sharer = GraphSharer(content: content)
sharer.failsOnInvalidData = true
sharer.completion = {
(result) in
print(result)
}
do {
try sharer.share()
}
catch (let error) {
print(error.localizedDescription)
}
I believe that I need to use the graphNode property to specify the destination page and that the correct format is as follows:
sharer.graphNode = "/\(pageId)"
However, when I set this property before posting, I am getting an error:
failed(Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
I've tried a dozen different formats to specify the node but they all return the same error and I can't find any working examples.
I managed to resolved this issue. It turns out that the graphNode path above is correct but I was looking in the wrong place due to the error message I was getting. Instead I just needed to specify the accessToken parameter.
graphSharer.accesstoken = myPageAccessToken
Note: The access token is not the user's current access token, but an access token you can retrieve when calling the /me/accounts API.
var graphPath = "/me/accounts"
I also then had an issue posting to the page because I had only requested the publish_actions permission. From the documentation, this appears to be suitable but it only worked where I requested further permissions as follows:
loginManager.logIn(withPublishPermissions: ["publish_actions",
"manage_pages", "publish_pages"], ...
Hopefully this will be of use to someone in future. :-)

Adding Firebase SDK somehow breaks facebook login for no apparent reason

I'm running Xcode beta 10, with ios 10 beta, and I got my facebook login working.
if I simply just add
import Firebase and FIRApp.configure() in my appdelegate, I get the following error:
Optional(Error Domain=com.facebook.sdk.core Code=8 "(null)" UserInfo={com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=0, com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=An active access token must be used to query information about the current user., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=2500, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey={
body = {
error = {
code = 2500;
"fbtrace_id" = CIheVvb2bpQ;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}})
This makes virtually no sense to me, I'm not doing anything with firebase yet, not trying to authenticate or track a login, why would simply importing firebase, and configuring it in the appdelegate cause this, and any ideas on how to fix?

Trying Login with Plaid APi

When i Login with plaid Api in live credential, it shows this type of error.
{
code = 1106;
message = "bad public_token";
resolve = "This public_token is corrupt or does not exist in our database. See https://plaid.com/docs/link for docs.";
}
so Any idea about that? Help me.

Facebook iOS SDK - extend expired token

I am having hard time trying to get the new extending-an-expired-token flow work.
When first-time user sign in the app over Facebook SSO, the token returned by Facebook usually expires in roughly 2 hours.
Facebook iOS SDK documentation makes the case simple.
extend expired token
So, I called "extendAccessTokenIfNeeded" according to the documentation. However, token refresh never happens. In the iOS SDK source, there's a global int const "kTokenExtendThreshold" set to 24 (hours).
My "extendAccessTokenIfNeeded" never invokes the real extend token logic.
To do a test, I called "extendAccessToken" instead.
Facebook returns the following error on this call:
Error Domain=facebookErrDomain Code=101 "The operation couldn’t be completed. (facebookErrDomain error 101.)" UserInfo=0x87e8820 {request_args=(
{
key = method;
value = "auth.extendSSOAccessToken";
},
{
key = format;
value = json;
},
{
key = sdk;
value = ios;
},
{
key = "sdk_version";
value = 2;
}
), error_msg=Invalid API key, error_code=101}
What the hell is going on?
I really appreciate any tips and comments. Is it that I missed something?
Thanks
Bill

Resources