Recently, the project began to have the requirement of sharing web pages on weibo. Before, it was always the requirement of sharing single pictures. I thought it would not be difficult to realize this requirement, but UNEXPECTEDLY, it gave me a small surprise. All right, without further ado, let’s begin the text. The microblog sharing in the project has been added for a long time. I thought it was just changing the way of sharing, which was not so complicated, but I encountered many difficulties in the process.

Enter the open platform of Weibo, download a Demo, and copy the code into the project according to the way in the Demo. The specific code is as follows:

WBMessageObject *message = [WBMessageObject message]; WBWebpageObject *webpage = [WBWebpageObject object]; webpage.objectID = @"identifier1"; Webpage. Title = NSLocalizedString(@" share webpage title ", nil); Webpage. The description = [nsstrings stringWithFormat: NSLocalizedString (@ "share web content abstract - %. 0 f", nil), [[NSDate date] timeIntervalSince1970]]; webpage.thumbnailData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image_2" ofType:@"jpg"]]; webpage.webpageUrl = @"http://weibo.com/p/1001603849727862021333?rightmod=1&wvr=6&mod=noticeboard"; message.mediaObject = webpage; WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request]; authRequest.redirectURI = @""; authRequest.scope = @"all"; WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token: nil]; [WeiboSDK sendRequest:request completion:nil];Copy the code

It was found that the picture was not displayed after being shared to Weibo, as shown below:

Check FAQ of Weibo open platform and find solutions to this problem as follows:

Q: Why is thumbnail not displayed after WBWebpageObject sharing? A: Mobile application business cooperation, the integration of LinkCard and attachment bar in mobile SDK sharing permission needs to apply for cooperation, please send email to [email protected] for business connectionCopy the code

Since it was said that I needed to apply for permissions, I went to the open platform to check the permissions, and found that all the permissions for this application had been applied, which was very embarrassing. What was the cause? It suddenly occurred to me that we could look at how other platforms did it, and found the page of Ele. me sharing webpage as shown in the following picture:

Seeing this way of sharing, I remembered the writing method of sharing pictures in the project. Then I splicing the content of sharing pictures and combining the title and sharing link into a new title. The specific code is as follows:

WBMessageObject *message = [WBMessageObject message]; message.text = [NSString stringWithFormat:@"%@ % @, "@" my skin report, "@" http://weibo.com/p/1001603849727862021333?rightmod=1&wvr=6&mod=noticeboard "); WBImageObject *imageObject = [WBImageObject object]; ImageObject. ImageData = UIImageJPEGRepresentation (self FXimage, 0.65); imageObject.delegate = self; message.imageObject = imageObject; WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request]; authRequest.redirectURI = @""; authRequest.scope = @"all"; WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token: nil]; [WeiboSDK sendRequest:request completion:nil];Copy the code

After running and sharing, it will look like the picture below:

Here, to achieve the needs of microblogging to share web pages. Finally, I would like to make fun of the document of weibo open platform, it is really written in disorder, I hope it can be improved, it is too difficult to find…