项目作者: stfalcon-studio

项目描述 :
Easy social network authorization for iOS. Supports Facebook, Vkontakte and Instagramm
高级语言: Swift
项目地址: git://github.com/stfalcon-studio/SocialToolKit.git
创建时间: 2017-03-20T14:58:55Z
项目社区:https://github.com/stfalcon-studio/SocialToolKit

开源协议:MIT License

下载


SocialToolKit

SocialToolKit purpose is to get access token from Facebook, VK or Instagram. You can use it to get token from specific social network, or from several (now supports only Facebook, VKontakte and Instagram).

How to install:

Requirements:

iOS 9.0+

Swift 3.0

Installing with CocoaPods:

  1. use_frameworks!
  2. pod 'SocialToolKit'

How to use:

For Facebook:

Update this three methods in your AppDelegate:

1.

  1. import SocialToolKit
  2. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  3. SocialToolKit.sharedInstance.appFBDidFinishLaunchingWithOptions(application: application, launchOptions: launchOptions)
  4. return true
  5. }
  6. func applicationDidBecomeActive(_ application: UIApplication) {
  7. SocialToolKit.sharedInstance.appFBDidBecomeActive()
  8. }
  9. func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
  10. SocialToolKit.sharedInstance.appFBOpenURL(app: app, url: url, options: options)
  11. return true
  12. }
  1. Go to Info.plist, secondary-clic Info.plist and select OpenAs -> SourceCode.

Insert the following XML snippet into the body of your file just before the final element.

  1. <key>CFBundleURLTypes</key>
  2. <array>
  3. <dict>
  4. <key>CFBundleURLSchemes</key>
  5. <array>
  6. <string>fb{your-app-id}</string>
  7. </array>
  8. </dict>
  9. </array>
  10. <key>FacebookAppID</key>
  11. <string>{your-app-id}</string>
  12. <key>FacebookDisplayName</key>
  13. <string>{your-app-name}</string>
  14. <key>LSApplicationQueriesSchemes</key>
  15. <array>
  16. <string>fbapi</string>
  17. <string>fb-messenger-api</string>
  18. <string>fbauth2</string>
  19. <string>fbshareextension</string>
  20. </array>
  • replace fb{your-app-id} with your Facebook app ID, prefixed with fb. For example, fb123456. You can find your app ID on the Facebook App Dashboard — https://developers.facebook.com/apps.
  • replace {your-app-id} with your app ID.
  • replace {your-app-name} with the display name you specified in the App Dashboard.
  • replace {human-readable reason for photo access} with the reason your app needs photo access.
  1. In yor viewController add as button-action (for example):
  1. import SocialToolKit
  2. SocialToolKit.sharedInstance.requestFacebookToken(permissions: ["public_profile", "user_friends"], loginBehavior: FBSDKLoginBehavior.systemAccount, { (token, error) in
  3. if error == nil {
  4. print("TOKEN: \(token)")
  5. } else {
  6. print("ERROR: \(error?.localizedDescription)")
  7. }
  8. })

For VK:

  1. Update this method in your AppDelegate:
  1. import SocialToolKit
  2. func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  3. SocialToolKit.sharedInstance.appVKOpenURL(sourceApplication: sourceApplication, url: url)
  4. return true
  5. }
  1. Go to Project -> Targets -> Info -> URL Types and add URL Schemes vk, for example:

URL Schemes: vk1234567
Role: Editor

  1. Go to Info.plist, secondary-clic Info.plist and select OpenAs -> SourceCode. And add AppTransportSequrity:

    1. <key>NSAppTransportSecurity</key>
    2. <dict>
    3. <key>NSExceptionDomains</key>
    4. <dict>
    5. <key>vk.com</key>
    6. <dict>
    7. <key>NSExceptionRequiresForwardSecrecy</key>
    8. false/>
    9. <key>NSIncludesSubdomains</key>
    10. <true></true>
    11. <key>NSExceptionAllowsInsecureHTTPLoads</key>
    12. <true></true>
    13. </dict>
    14. </dict>
    15. </dict>
  2. Add (update) LSApplicationQueriesSchemes:

    1. <key>LSApplicationQueriesSchemes</key>
    2. <array>
    3. <string>vk</string>
    4. <string>vk-share</string>
    5. <string>vkauthorize</string>
    6. </array>

    If you are using FB iOS SDK and VK iOS SDK it looks like this:

    1. <key>LSApplicationQueriesSchemes</key>
    2. <array>
    3. <string>fbapi</string>
    4. <string>fb-messenger-api</string>
    5. <string>fbauth2</string>
    6. <string>fbshareextension</string>
    7. <string>vk</string>
    8. <string>vk-share</string>
    9. <string>vkauthorize</string>
    10. </array>
  3. Then in ViewController (for example) use:

  1. SocialToolKit.sharedInstance.requestVKToken(permissions: ["friends", "photos"], appId: "your app id") { (token, error) in
  2. if error == nil {
  3. print("TOKEN: \(token)")
  4. } else {
  5. print("ERROR: \(error?.localizedDescription)")
  6. }
  7. }

For Instagramm:

  1. In ViewController:
  1. @IBAction func instagramAction(_ sender: Any) {
  2. SocialToolKit.sharedInstance.requestInstagramToken(permissions: ["basic"], clientID: "your cliend id", redirectURI: "your redirect uri") { token, error in
  3. print(token)
  4. print(error?.localizedDescription)
  5. }
  6. }
  1. Register the client on https://www.instagram.com/developer
  2. Then go to Manage Clients -> Security -> uncheck Disable implicit OAuth.
  3. Add your redirect uri in Valid redirect URIs.

LICENCE:

Copyright (c) 2017 Stfalcon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.