Android implementation of sina Weibo one click sharing example code

Before this chapter

More and more apps support the function of one click sharing to QQ space, wechat circle of friends and Sina Weibo. At the same time, they also support the login of third-party accounts, such as accounts of third-party platforms such as QQ, wechat and Sina Weibo. This chapter integrates a set of shared source code with the current popular design, taking into account the free open source sharesdk and the actual needs of the project. All rights are reserved. If you need to reprint, please indicate the reprint address.

1. Development environment and SDK Download

Development tool: Android studio version 2.1.3

Sharesdk: download the latest version of social sharing sharesdk 2.7.7 from the official website of mob (www.mob. Com). Unzip it as shown in the figure

Enter the sharesdk for Android file, find the quickintegrator.jar file, double-click to open it according to the official website, and integrate the third-party platform according to the needs. In some cases, if double clicking cannot open it, under Windows system, enter CMD, find the current directory of quickintegrator.jar, type Java - jar quickintegrator.jar, and integrate the third-party platform according to the actual needs, Finally, the sample folder is generated, including LIBS and other files to be used

Copy all the contents under the newly generated folder sample to your own project. At the same time, you need to add library dependencies on the jar files added to LIBS

Mob enters the background, applies for sharing permission, and obtains app key and app secret

Replace the requested app key

2. Configure androidmanifest.xml

3. Add the necessary activity information

Note: in the above code, there is a sharing callback about wechat and QQ. This article only describes the sharing use of sina Weibo, and the activity addition of QQ and wechat can be used for reference

4. Replace the appkey applied by the mob background with the key applied by each platform

Replace appkey in sharesdk.xml under aseests, and add appkey and appsecret required by third-party applications. Take Sina Weibo as an example

4.1 Sina Weibo key application

1) Log in to Sina Weibo, apply, fill in the account, apply for registration and other information. Take an individual as an example. After the application is completed, obtain the permission of "micro connection" and click "create micro connection now";

2) Fill in the application name and check the application platform, taking android as an example;

3) Confirm the submission to obtain the app key and secret

4) Sina Weibo obtains the Android package name and signature of the app

5) Obtain the package name by entering the androidmanifest.xml under the application name "Android instance" app;

6) Android signature acquisition

Through the signature tool provided by Sina Weibo in 4), install the "app_signatures. APK" downloaded by GitHub to the mobile phone, install the app "Android instance" to the mobile phone, and enter the Android package name to generate the corresponding Android signature

7) Sina Weibo test authority

It should be noted that the app has not been launched at this time and has not passed the audit. For the time being, only the test permission can be associated with 15 test accounts;

5. Formal programming

This part includes the pop-up dialog box at the bottom of one button, button operation, third-party sharing and other operations;

5.1 custom dialog

Refer to several blogs and summarize the dialog you need.

The dialog box is shown in the figure;

5.2 sharesdk initialization

It needs to be initialized in the activity sharing interface or in the oncreate() function of mainactivity

5.3 obtain and save screenshots of the current screen for sharing with third parties

As a third-party sharing point, how to share the screenshot of the screen to Sina Weibo with one click.

5.4 listening events

Click Sina Weibo to directly pop up the graphic sharing interface. The required pictures are screenshots of the current screen. At the same time, load the text you added and the URL link. This part can be used as the URL download link for app sharing. The following code also gives some other use cases shared by Sina Weibo, It can be changed according to personal preferences or the actual needs of the project;

6. Sina Weibo instance sharing

After using the sharesdk correctly, click the graphic button of sina Weibo to pop up the picture and text sharing box as shown in the figure below, which can be completed by entering text.

As shown in the figure

Note: if you share the website link, you must add "http: / /", otherwise only www.baidu.com will be shared

Note: after the sharing is successful, there will be a response prompt. You need to add it yourself. Log in to Sina Weibo to see the sharing of personal information. Because it is not online, it "comes from an unapproved application". When you click "Baidu", you can jump to the interface

Through the explanation of the above core parts, we should have a basic understanding and use ability of sina Weibo sharing. The specific details, such as how to create interfaces, buttons and queries, were not explained too much. If necessary, you can send me a simple letter or leave a message directly.

In addition, please help correct any incomprehension, objection or incorrect part of the above knowledge. Thank you.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>