How to share images on Pinterest using the latest iOS SDK

I want to share the image on Pinterest. I set up the Pinterest iOS SDK without CocoaPods.

I wrote code that forces me to redirect the Pinterest application and get authorization. But after that I did not receive any answer.

In the previous version of the iOS SDK, we should only pass the URL of this image. But now he also asks for the identifier Board.

I do not know how to get the board ID and share them on Pinterest, since I do not receive a response from the success block.

This is the code I'm using.

[[PDKClient sharedInstance] authenticateWithPermissions:[NSArray arrayWithObjects:PDKClientReadPublicPermissions, nil] withSuccess:^(PDKResponseObject *responseObject) { NSLog(@"Response Object:%@",responseObject); } andFailure:^(NSError *error) { NSLog(@"Error:%@",error); }]; 

I have been trying this for the past week. Please suggest me where I make mistakes.

Thanks.

+5
source share
3 answers

I solved this problem and I would like to thank the people who helped me. Now I can share the image on Pinterest. I gave an example application from this Github link https://github.com/pinterest/ios-pdk to share the image on Pinterest. Here are the steps I followed.

1) I installed the Pinterest SDK using Cocoapods.

2) I added the line below to didFinishLaunchingWithOptions

 [PDKClient configureSharedInstanceWithAppId:@"1234566"]; 

3) I added the following two functions to the AppDelegate.m file

 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [[PDKClient sharedInstance] handleCallbackURL:url]; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { return [[PDKClient sharedInstance] handleCallbackURL:url]; } 

4) I added the code below to the action of the image sharing button.

 [PDKPin pinWithImageURL:[NSURL URLWithString:@"https://about.pinterest.com/sites/about/files/logo.jpg"] link:[NSURL URLWithString:@"https://www.pinterest.com"] suggestedBoardName:@"Testing" note:@"The Pinterest Logo" withSuccess:^ { // weakSelf.resultLabel.text = [NSString stringWithFormat:@"successfully pinned pin"]; } andFailure:^(NSError *error) { //weakSelf.resultLabel.text = @"pin it failed"; NSLog(@"Error:%@",error); }]; 
+3
source

You can get board information using Pinterest api through the following code:

 PDKClient.sharedInstance().getAuthenticatedUserBoardsWithFields(NSSet(array: ["id","image","description","name"]) as Set<NSObject>, success: { (responseObject: PDKResponseObject!) -> Void in self.currentResponseObject = responseObject self.boardsArray = responseObject.boards() print("self.boards are \(self.boardsArray)") //Contains identifiers(board-id) which is used for image sharing }) { (err :NSError!) -> Void in print("e rror NSError: \(err)") self.hideHUD() } 
+1
source
 #import <PinterestSDK/PDKPin.h> -(void)shareOnPinterestUsingSDKWithText:(NSString*)text andURL:(NSURL*)imageUrl Image:(UIImage*)imagePinterest completionHandler:(void (^)(BOOL completed))completion{ [PDKPin pinWithImageURL:imageUrl link:imageUrl suggestedBoardName:@"" note:text withSuccess:^{ NSLog(@"success"); completion(true); } andFailure:^(NSError *error) { NSLog(@"error %@", error); completion(false); }]; } TODO:- 1) Install SDK using cocopods pod 'PinterestSDK', '~> 1.0' 2) Add pinterest app id in Appdelegate static NSString* const kPinterestAppId = @'{PINTEREST_ID}'; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [PDKClient configureSharedInstanceWithAppId: kPinterestAppId]; Return true; } 3) Add pinterest key in info.plist <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>${BUNDLE_IDENTIFIER}</string> <key>CFBundleURLSchemes</key> <array> <string>${APP_URL_SCHEME}</string> <string>pdk${PINTEREST_ID}</string> </array> </dict> </array> =========================================================== <key>LSApplicationQueriesSchemes</key> <array> <string>pinterestsdk.v1</string> </array> =========================================================== <key>PinterestAppId</key> <string>${PINTEREST_ID}</string> =========================================================== 4) For handling callback when pinterest sharing done and control return to app -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options { NSString *pinterestKey = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"PinterestAppId"]; if (pinterestKey && ![pinterestKey isKindOfClass:[NSNull class]]) { pinterestKey = [NSString stringWithFormat:@"pdk%@", pinterestKey]; if ([urlStr rangeOfString:pinterestKey].location != NSNotFound) { return [[PDKClient sharedInstance] handleCallbackURL:url]; } } } 
0
source

Source: https://habr.com/ru/post/1245222/


All Articles