I am trying to share a url, image and a text to linkedin through my app. But it shows an error as
The operation couldn’t be completed. (LISDKErrorAPIDomain error 403.)
My code is
func didLinkedinBtnPressed(cellObject: MyModel) {
let tmp = ["comment": cellObject.strSocialText!,
"content": ["title":"AppName", "description":cellObject.strSocialText!,"submitted-url":cellObject.strWebSite!,"submitted-image-url":cellObject.strImageUrl!],"visibility": ["code": "anyone"]] as [String : Any]
print("PostDtaa = \(tmp)")
let postData = try? JSONSerialization.data(withJSONObject: tmp, options: .prettyPrinted)
let url = NSString(string:"https://api.linkedin.com/v1/people/~/shares?format=json")
let permissions: [AnyObject] = [LISDK_BASIC_PROFILE_PERMISSION as AnyObject, LISDK_EMAILADDRESS_PERMISSION as AnyObject,LISDK_W_SHARE_PERMISSION as AnyObject]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (success) -> () in
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().postRequest(url as String, body: postData, success: { (_ response) in
print(response ?? "")
self.simpleAlert(titleOfAlert: "Success", messageOfAlert: "Shared Successfully")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
}, error: { (_errorRes) in
print(_errorRes?.localizedDescription ?? "No Error!!!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
}, errorBlock: { (error) -> () in
print("%s", "error called!")
LISDKAPIHelper.sharedInstance().cancelCalls()
LISDKSessionManager.clearSession()
})
}
Why am i getting a 403 error here?
I experimented a similar issue in the past it was related to the w_share permission
from the linkedin doc
Required permission: w_share
Whether set as a default permission in your app settings or requested
specifically via the scope argument during your authentication
process, you will need to request the w_share member permission in
order for your application to successfully make the API call to share
content.
w_share is disabled by default so it has to be explicitly enabled
NOTE: the token could be cached by app so in order to be sure that a new token (with the updated permissions) is used, I strongly suggest you to uninstall everything from your mobile device and re-install it again.
Related
I am trying to login with LinkedIn using the native app and the LinkedIn SDK. So far I can login using the web if the LinkedIn app is not installed. I can also login with LinkedIn and get a token in return. But when I try to authenticate with Firebase I get this error:
Optional(Error Domain=FIRAuthErrorDomain Code=17000 "The custom token
format is incorrect. Please check the documentation." UserInfo=
{NSLocalizedDescription=The custom token format is incorrect. Please
check the documentation., error_name=ERROR_INVALID_CUSTOM_TOKEN})
This is my code:
// App installed
let permissions = [LISDK_BASIC_PROFILE_PERMISSION,LISDK_EMAILADDRESS_PERMISSION]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: { (returnState) -> Void in
LISDKAPIHelper.sharedInstance().getRequest("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,public-profile-url,industry,positions,location)?format=json", success: { (response) -> Void in
if let data = response?.data.data(using: String.Encoding.utf8) {
if let dictResponse = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers){
let token = LISDKSessionManager.sharedInstance().session.accessToken.accessTokenValue
Auth.auth().signIn(withCustomToken: token! ) { (user, error) in
print(user!)
print(error!)
}
}
}
}, error: { (error) -> Void in
print("LINKEDIN error\(String(describing: error))")
})
}) { (error) -> Void in
print("error login linkedin")
}
The token I am sending to Firebase is a String, so that should be okay. I must be missing something. But what ?
The problem was my misunderstanding. I thought I could use the Linkedin token directly. It has to go to a webservice that uses the Firebase admin user to generate the token.
Note: please do not close as duplicate, I went through almost every existing thread here on Stackoverflow, but my problem is still not solved.
This is my Swift 3 function with the latest Facebook SDK:
let req = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"email,name"], tokenString: token?.tokenString, version: nil, httpMethod: "GET")
_ = req?.start(completionHandler: { (connection, result, error : Error?) -> Void in
if(error == nil) {
print("result \(result)")
} else {
print("error \(error!)")
}
})
Result:
result Optional({
id = 102080884567XXXXX;
name = "David Seek";
})
Email permission is approved:
Also the App is in live mode:
I have checked the reference guide, but I can't find my mistake.
My problem is, that I'm saving the facebookID as Email adress into my backend and I'm trying to figure out why... Therefore I have tried the provided code on top, but I'm not receiving the Email.
let result = FBSDKApplicationDelegate.sharedInstance().application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
if result {
let token = FBSDKAccessToken.current()
let fieldsMapping = [
"id" : "facebookId",
"name" : "name",
"birthday": "birthday",
"first_name": "fb_first_name",
"last_name" : "fb_last_name",
"gender": "gender",
"email": "email"
]
backendless?.userService.login(withFacebookSDK: token, fieldsMapping: fieldsMapping, response: { (user: BackendlessUser?) in
}, error: { (fault: Fault?) -> Void in
print("Server reported an error: \(fault)")
})
}
I'm receiving every information, but the Email...
What am I missing? Help is very appreciated.
Email permission is granted:
That is not what that screenshot shows. It shows that it is approved, meaning your app can ask users for it. But it still has to ask.
Make sure that has happend successfully - either by debugging the access token, or via an API call to /me/permissions
You need to ask the user for permission during login.
I'm using the mobile SDK for iOS (Version:1.0.7) to share something on LinkedIn. I can get the current account information, but when I try to share on LinkedIn,it always feedback the error description. This is my code:
let url:String = "https://api.linkedin.com/v1/people/~/shares"
let payload:String = "{\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\",\"visibility\":{\"code\":\"anyone\"}}"
if LISDKSessionManager.hasValidSession(){
LISDKAPIHelper.sharedInstance().postRequest(url, stringBody: payload, success: { (response) -> Void in
print("\(response.data)")
}, error: { (apiError) -> Void in
print("\(apiError.description)")
})
Has anyone ever facing the same issue. Please help me,thanks a lot!
This works in Swift:-
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().postRequest(url, stringBody: payload, success: {
response in
//Do something with the response
print("\(response.data)")
}, error: {
error in
//Do something with the error
print("\(error.description)")
})
}
I had the same problem when I didn't set the correct permissions.
Make sure create session with share permissions.
let permissions = [LISDK_BASIC_PROFILE_PERMISSION, LISDK_W_SHARE_PERMISSION]
LISDKSessionManager.createSession(withAuth: permissions, state: nil, showGoToAppStoreDialog: true, successBlock: ...
I have integrated twitter kit in my ios app by following https://dev.twitter.com/twitter-kit/ios/configure this. I could sign-in after authentication and see my twitter name easily but now i want to retrieve my email address so i used TWTRShareEmailViewController which presents user a share email view which returns null. I went through the docs where they mentioned about my app to be whitelisted for requesting email permission and said to fill up this form https://support.twitter.com/forms/platform am not getting what to do next? how to get i user email permission exactly? Suggest any help. Thanks in advance.
I didn't find a specific form to ask to be whitelisted neither. I went on their form link https://support.twitter.com/forms/platform and I checked the "I have an API policy question not covered by these points" option. They responded a few days after and asked me more information about the application and its app ID. I'm actually waiting for their answer.
EDIT:
So after several (a lot) emails with support#fabric.io and a few bugs I finally got whitelisted. But the option is currently unavailable with Fabric so you'll have to create a Twitter app on apps.twitter.com. Just send a mail with your app ID or your keys. They'll probably ask you a quick description of your app and it shouldn't take so much time to be whitelisted. Good luck!
After having a conversation with sdk-feedback#twitter.com, I got my App whitelisted. Here is the story:
Send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email address inside your App.
They will review your App and reply to you within 2-3 business days.
Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:
On the 'Settings' tab, add a terms of service and privacy policy URL
On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.
It's time to code:
-(void)requestUserEmail
{
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
} else {
// Handle user not signed in (e.g. attempt to log in or show an alert)
}
}
Hope it helps !!!
Send email to sdk-feedback#twitter.com to whitelist your twitter login app first.
Swift 3.0 Code with fabric
#IBAction func btnTwitterAction(_ sender: AnyObject) {
Twitter.sharedInstance().logIn { (session, error) in
if session != nil {
print("signed in as \(session!.userName)");
let client = TWTRAPIClient.withCurrentUser()
let request = client.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
client.sendTwitterRequest(request) { response, data, connectionError in
if (connectionError == nil) {
do{
let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String:Any]
print("Json response: ", json)
let firstName = json["name"]
let lastName = json["screen_name"]
let email = json["email"]
print("First name: ",firstName)
print("Last name: ",lastName)
print("Email: ",email)
} catch {
}
}
else {
print("Error: \(connectionError)")
}
}
} else {
NSLog("Login error: %#", error!.localizedDescription);
}
}
}
How to get email id in twitter ?
Step 1 : got to https://apps.twitter.com/app/
Step 2 : click on ur app > click on permission tab .
Step 3 : here check the email box
I've faced the same issue recently
Here is what you should try if you are using new twitter kit
Go to
https://apps.twitter.com/
Select permissions tab
Set it to Read Only
Code :
Twitter.sharedInstance().logIn(withMethods: [.webBased,.systemAccounts,.all]) {(session, error) -> Void in
if (session != nil) {
print("signed in as \(session?.userName)");
let client = TWTRAPIClient(userID: session?.userName)
client.loadUser(withID: (session?.userID)!, completion: { (user, error) in
let twitterClient = TWTRAPIClient.withCurrentUser()
let request = twitterClient.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
twitterClient.sendTwitterRequest(request) { response, data, connectionError in
print(data!)
let s :String = String(data: data! as Data, encoding: String.Encoding.utf8)!
//
// let json = try JSONSerialization.jsonObject(with: responseData as Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? [String:AnyObject]
//
Twitter.sharedInstance().sessionStore.logOutUserID((session?.userID)!)
if let data = s.data(using: String.Encoding.utf8) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
print(json!)
} catch {
print("Something went wrong")
}
}
}
})
} else {
}
I have integrated twitter kit in my ios app by following https://dev.twitter.com/twitter-kit/ios/configure this. I could sign-in after authentication and see my twitter name easily but now i want to retrieve my email address so i used TWTRShareEmailViewController which presents user a share email view which returns null. I went through the docs where they mentioned about my app to be whitelisted for requesting email permission and said to fill up this form https://support.twitter.com/forms/platform am not getting what to do next? how to get i user email permission exactly? Suggest any help. Thanks in advance.
I didn't find a specific form to ask to be whitelisted neither. I went on their form link https://support.twitter.com/forms/platform and I checked the "I have an API policy question not covered by these points" option. They responded a few days after and asked me more information about the application and its app ID. I'm actually waiting for their answer.
EDIT:
So after several (a lot) emails with support#fabric.io and a few bugs I finally got whitelisted. But the option is currently unavailable with Fabric so you'll have to create a Twitter app on apps.twitter.com. Just send a mail with your app ID or your keys. They'll probably ask you a quick description of your app and it shouldn't take so much time to be whitelisted. Good luck!
After having a conversation with sdk-feedback#twitter.com, I got my App whitelisted. Here is the story:
Send mail to sdk-feedback#twitter.com with some details about your App like Consumer key, App Store link of an App, Link to privacy policy, Metadata, Instructions on how to log into our App. Mention in mail that you want to access user email address inside your App.
They will review your App and reply to you within 2-3 business days.
Once they say that your App is whitelisted, update your App's settings in Twitter Developer portal. Sign in to apps.twitter.com and:
On the 'Settings' tab, add a terms of service and privacy policy URL
On the 'Permissions' tab, change your token's scope to request email. This option will only been seen, once your App gets whitelisted.
It's time to code:
-(void)requestUserEmail
{
if ([[Twitter sharedInstance] session]) {
TWTRShareEmailViewController *shareEmailViewController =
[[TWTRShareEmailViewController alloc]
initWithCompletion:^(NSString *email, NSError *error) {
NSLog(#"Email %# | Error: %#", email, error);
}];
[self presentViewController:shareEmailViewController
animated:YES
completion:nil];
} else {
// Handle user not signed in (e.g. attempt to log in or show an alert)
}
}
Hope it helps !!!
Send email to sdk-feedback#twitter.com to whitelist your twitter login app first.
Swift 3.0 Code with fabric
#IBAction func btnTwitterAction(_ sender: AnyObject) {
Twitter.sharedInstance().logIn { (session, error) in
if session != nil {
print("signed in as \(session!.userName)");
let client = TWTRAPIClient.withCurrentUser()
let request = client.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
client.sendTwitterRequest(request) { response, data, connectionError in
if (connectionError == nil) {
do{
let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String:Any]
print("Json response: ", json)
let firstName = json["name"]
let lastName = json["screen_name"]
let email = json["email"]
print("First name: ",firstName)
print("Last name: ",lastName)
print("Email: ",email)
} catch {
}
}
else {
print("Error: \(connectionError)")
}
}
} else {
NSLog("Login error: %#", error!.localizedDescription);
}
}
}
How to get email id in twitter ?
Step 1 : got to https://apps.twitter.com/app/
Step 2 : click on ur app > click on permission tab .
Step 3 : here check the email box
I've faced the same issue recently
Here is what you should try if you are using new twitter kit
Go to
https://apps.twitter.com/
Select permissions tab
Set it to Read Only
Code :
Twitter.sharedInstance().logIn(withMethods: [.webBased,.systemAccounts,.all]) {(session, error) -> Void in
if (session != nil) {
print("signed in as \(session?.userName)");
let client = TWTRAPIClient(userID: session?.userName)
client.loadUser(withID: (session?.userID)!, completion: { (user, error) in
let twitterClient = TWTRAPIClient.withCurrentUser()
let request = twitterClient.urlRequest(withMethod: "GET",
url: "https://api.twitter.com/1.1/account/verify_credentials.json",
parameters: ["include_email": "true", "skip_status": "true"],
error: nil)
twitterClient.sendTwitterRequest(request) { response, data, connectionError in
print(data!)
let s :String = String(data: data! as Data, encoding: String.Encoding.utf8)!
//
// let json = try JSONSerialization.jsonObject(with: responseData as Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as? [String:AnyObject]
//
Twitter.sharedInstance().sessionStore.logOutUserID((session?.userID)!)
if let data = s.data(using: String.Encoding.utf8) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
print(json!)
} catch {
print("Something went wrong")
}
}
}
})
} else {
}