- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我开始使用 Swift 开发 iOS 应用。现在我正处于需要创建登录系统的部分。但是,我们需要人们提供的 LinkedIn 信息。
我如何在 iOS 中使用 OAuth2 API 来实现这一点?
我已经在 LinkedIn 开发人员区域创建了一个应用程序,但现在我卡住了。我从某人那里得到一些建议,我需要使用 UIWebView
,但我不知道它是如何工作的。
最佳答案
在 Swift 应用程序中集成 LinkedIn 登录
首先,下载 LinkedIn iOS SDK .我将在此示例中使用 1.07 稳定版。我将遵循集成指南 here .
linkedin-sdk.framework
库复制到您的应用程序。确保选中“必要时复制文件”和“为文件夹引用创建组”。项目设置完成,现在让我们写一些代码吧!
创建一个名为 BridgingHeader.h
的新头文件。在 Targets -> YourApp -> Build Settings -> Swift Compiler - Code Generation 下,将 MyApp/BridgingHeader.h
添加到“Objective-C Bridging Header”。
在您的 BridgingHeader.h
中,添加以下两行:
#import <Foundation/Foundation.h>
#import <linkedin-sdk/LISDK.h>
在您的 AppDelegate.swift 中,添加此代码以处理 OAuth URL 回调:
swift 3:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if LISDKCallbackHandler.shouldHandle(url) {
return LISDKCallbackHandler.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
return true
}
swift 2.x:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
if LISDKCallbackHandler.shouldHandleUrl(url) {
return LISDKCallbackHandler.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
return true
}
现在是登录用户的时候了。在您的 View Controller 中,假设您有一个“登录”按钮。您的 IBAction
可能如下所示:
@IBAction func doLogin(sender: AnyObject) {
LISDKSessionManager.createSessionWithAuth([LISDK_BASIC_PROFILE_PERMISSION], state: nil, showGoToAppStoreDialog: true, successBlock: { (returnState) -> Void in
print("success called!")
let session = LISDKSessionManager.sharedInstance().session
}) { (error) -> Void in
print("Error: \(error)")
}
}
登录时,系统会要求用户对您的应用程序进行身份验证:
如果用户允许,将调用成功 block ,您可以获得有关已通过身份验证的用户的信息。如果登录失败或用户不允许访问,则会调用失败 block ,您可以就发生的问题提醒用户。
要获取有关我们通过身份验证的用户的信息,请对用户的个人资料调用 GET 请求:
let url = "https://api.linkedin.com/v1/people/~"
if LISDKSessionManager.hasValidSession() {
LISDKAPIHelper.sharedInstance().getRequest(url, success: { (response) -> Void in
print(response)
}, error: { (error) -> Void in
print(error)
})
}
response.data
将包含有关经过身份验证的用户的信息:
"{\n \"firstName\": \"Josh\",\n \"headline\": \"Senior Mobile Engineer at A+E Networks\",\n ... }"
阅读docs进一步了解您可以使用 API 执行的更多操作。
可以找到一个示例项目(我的 App ID 被混淆了)here .
关于iOS linkedin 认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28491280/
创建我们的产品 LinkedIn 应用程序的开发人员通过 developer.linkedin.com 在他的个人 LinkedIn 帐户下添加了它。我们想将此应用程序移至我们公司的 LinkedIn
我正在尝试使用linkedin API 来显示我从第一天开始发布的个人资料的提要。帖子包括媒体、图像、视频等。我想知道是否有任何可用的 API,我可以在其中传递一些参数并获取我的linkedin 个人
我的应用程序从 LinkedIn 获取用户信息,但我找不到从 LinkedIn 获取某人性别的方法。 是否可以? LinkedIn 甚至有性别字段吗? 最佳答案 不。检查这个; https://dev
我很难在 LinkedIn 上获得分享。我正在尝试通过 LinkedIn API V2 发布 LinkedIn 共享,每次我发出发布请求时,我都会收到来自服务器的请求超时(状态 504)答复。这是我的
LinkedIn 的 API 返回以下值: [creationTimestamp] => 1407247548000 它看起来类似于 UNIX 时间戳,但末尾有三个“额外”零。这是什么格式,我该如何解
我正在尝试将从 ugcPosts API 获取组织帖子的现有代码迁移到 Posts API 的新版本调用(版本 202210),但我遇到了获取文章缩略图的问题。我从 Posts API 获得的响应不包
标题几乎说明了一切。有什么方法可以访问 LinkedIn 上大学页面的提要/更新吗? 在他们的开发者网站上唯一提到的大学是他们的 Alumni 小部件。 最佳答案 一句话:没有。 对于 API 的所有
您知道是否可以为 LinkedIn 平台构建应用程序? 最佳答案 是的,他们在 http://developer.linkedin.com/index.jspa 有 API ,允许访问个人资料、连接、
在 LinkedIn 的 API 使用条款 (https://developer.linkedin.com/legal/api-terms-of-use) 的第 2.3 节中,他们提到开发人员最多可以
作为公司页面的管理员,我如何通过 LinkedIn api 访问该公司的帖子 我被要求成为我公司资料的管理员。我创建了一个应用程序并将我的公司映射到该应用程序。但奇怪的是我刚刚获得了该应用程序的三个权
如何为我的网站提取或获取 LinkedIn 推荐?是否有任何插件或 PHP 脚本? 最佳答案 您可以使用 LinkedIn API 提取建议。 ,特别是 Profile API .粗略的步骤是: 创建
我正在为公司建立外部网站,我想展示我们公司的 LinkedIn 个人资料 最近更新 在我们的网站内。目前,当我访问我们公司的 LinkedIn 个人资料时,我可以看到这些最近的更新,这些更新也可供公共
articles API 的 LinkedIn 文档表明我可以通过做一个特定的文章的内容等 GET https://api.linkedin.com/v2/originalArticles/{orig
我想按日期范围获取视频分析。 我关注了视频分析 API, https://learn.microsoft.com/en-us/linkedin/marketing/integrations/commu
我想在我的网站中添加添加个人资料按钮以进行认证,以便用户可以将其添加到他们链接的个人资料中。 为此,我正在使用 任何人都可以帮助这里如何自动归档文件?意味着我想从我的一端发送证书名称、链接、许可证。
当图像通过 LinkedIn API v2 共享到个人资料(而非公司)时,它会显示为好像被裁剪过的一样: 但是,当我在 www.linkedin.com 上上传并分享同一张图片到我的个人资料时,它不显
当图像通过 LinkedIn API v2 共享到个人资料(而非公司)时,它会显示为好像被裁剪过的一样: 但是,当我在 www.linkedin.com 上上传并分享同一张图片到我的个人资料时,它不显
我正在使用 LinkedIn Owin Middleare,今天早上开始遇到问题,现在已将其复制到以下错误: POST https://www.linkedin.com/uas/oauth2/acce
我在我的网站上使用 LinkedIn 分享按钮,我使用相同的脚本将页面分享到 LinkedIn。但是,某些页面是成功的。一些页面失败。这是错误信息 Error while processing rou
有没有一种方法可以使用 LinkedIn API 提取公司洞察信息?我有一个高级帐户,并在 LinkedIn 开发者平台上创建了一个应用程序。我似乎找不到获取公司数据的方法,例如员 worker 数(
我是一名优秀的程序员,十分优秀!