<<<<<<< HEAD MODIFIED VERSION OF ASNE
Differences
- No need for having it instantiated inside a fragment. Can be made application wide available by adding it in your MainActivity
- Currently only working with facebook, google plus, vkontakte and twitter. Easy to fix the others
Code in MainActivity
public SocialNetworkManager socialManager;
public FacebookSocialNetwork fbNetwork;
public TwitterSocialNetwork tnetwork;
public VkSocialNetwork vnetwork;
public GooglePlusSocialNetwork gnetwork;
private void initSocialNetworks(){
try {
ArrayList<String> fbScope = new ArrayList<String>();
fbScope.addAll(Arrays.asList("public_profile, email, user_friends"));
SocialNetworkManager mSocialNetworkManager = (SocialNetworkManager) (getSupportFragmentManager().findFragmentByTag("sociallogin"));
//hack because sometimes the social network gives null result when activty is restored from non saved instance
if (mSocialNetworkManager != null) {
try {
mSocialNetworkManager.getSocialNetwork(FacebookSocialNetwork.ID);
} catch (SocialNetworkException e) {
mSocialNetworkManager = null;
}
}
String[] vkScope = new String[0];
Log.d(TAG, "create social manager");
mSocialNetworkManager = new SocialNetworkManager();
socialManager = mSocialNetworkManager;
fbNetwork = new FacebookSocialNetwork(mSocialNetworkManager, this, fbScope);
tnetwork = new TwitterSocialNetwork(mSocialNetworkManager, this, "{{key}}", "{{key2", "http://boogoo.android.app/");
vnetwork = new VkSocialNetwork(mSocialNetworkManager, this, "{{key}}", vkScope);
gnetwork = new GooglePlusSocialNetwork(mSocialNetworkManager, this);
mSocialNetworkManager.addSocialNetwork(fbNetwork);
mSocialNetworkManager.addSocialNetwork(tnetwork);
mSocialNetworkManager.addSocialNetwork(vnetwork);
mSocialNetworkManager.addSocialNetwork(gnetwork);
getSupportFragmentManager().beginTransaction().add(mSocialNetworkManager, "sociallogin").commit();
}
catch(Exception e){
Log.e(TAG,"error initializing social networks "+e.getMessage());
}
}
Implementation code would be something like:
//find existing logged in network type
final int logged_in_network = getActivity().getPreferences(0).getInt("social_network_id", -1);
SocialNetwork socialNetwork = null;
if (logged_in_network != -1) {
Log.d(TAG,"found prev logged in network "+logged_in_network);
socialNetwork = ((MainActivity) getActivity()).socialManager.getSocialNetwork(logged_in_network);
}
//if user is connected to an existing network
if (socialNetwork != null && logged_in_network != -1 && socialNetwork.isConnected()) {
Log.d(TAG, "network is connected");
try {
socialNetwork.requestCurrentPerson(new OnRequestSocialPersonCompleteListener() {
@Override
public void onRequestSocialPersonSuccess(int i, SocialPerson socialPerson) {
Log.d(TAG, "on person request " + socialPerson.toString());
User u = new User();
u.username = socialPerson.name;
u.profileImage = socialPerson.avatarURL;
u.id = socialPerson.id;
u.networkid = logged_in_network + "";
}
@Override
public void onError(int i, String s, String s2, Object o) {
Log.e(TAG, "error " + s + "---" + s2);
Toast.makeText(getActivity(), "ERROR: " + s, Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
Log.e(TAG, "error get person " + e.getMessage());
}
//if user is not logged in
} else {
//Usualy you want to add a dialog fragment here with a list of social networks.
//After clicking a social network you would get a networkid
final SocialNetwork socialNetwork = ((MainActivity) getActivity()).socialManager.getSocialNetwork(networkid);
//cancel all previous operations
socialNetwork.cancelAll();
Log.d(TAG, "request login networkid: " + networkid);
socialNetwork.requestLogin(new OnLoginCompleteListener() {
@Override
public void onLoginSuccess(final int networkid) {
Log.d(TAG, " login succes");
socialNetwork.requestCurrentPerson(new OnRequestSocialPersonCompleteListener() {
@Override
public void onRequestSocialPersonSuccess(int i, SocialPerson socialPerson) {
Log.d(TAG, "on account receive success" + socialPerson.toString());
User u = new User();
u.username = socialPerson.name;
u.id = socialPerson.id;
u.networkid = networkid + "";
u.profileImage = socialPerson.avatarURL;
}
@Override
public void onError(int i, String s, String s2, Object o) {
Log.e(TAG, "error " + s + "---" + s2);
Toast.makeText(getActivity(), "on account receive error: " + s, Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onError(int i, String s, String s2, Object o) {
try {
Log.e(TAG, " login error " + s + "---" + s2);
Toast.makeText(getActivity(), "Login error: " + s, Toast.LENGTH_LONG).show();
}
catch(Exception e){
}
newFragment.dismissAllowingStateLoss();
}
});
}
======= Unfreeze project - merge all puls for master branch - current version was not tested - NOT STABLE
Sorry, but I freeze work on project for some time(I hope not long, nearly month) - too busy. I saw all Issues and will resolve them as soon as I can.
91bf48d9fc2560400bc6210eb95a8eb68a76920f
ASNE library created for simple integration of social setworks to android applications. If you want to integrate your application with multiple social networks just choose ASNE modules and add them to your project. You just need to: add module, build SocialNetworkManager and configure your AndroidManiferst. ASNE contains common interface for most popular social networks, but you can easily make module for another.
ASNE contains modules for social networks:
- Google Plus
- Vkontakte
- Odnoklassniki
Features
Documentation
Demo app
Getting started
Important
Developed By
License
ASNE got almost all necessary requests to social networks
- Login
- Configure necessary permissions
- Get Access Token
- Get current person social profile
- Get social profile of user by id
- Get social profile for array of users
- Get detailed user profile
- Share message
- Share photo
- Share link
- Request Share dialog with message/photo/link
- Check is user(by id) is friend of current
- Get list of Friends
- Adding friends by id
- Remove friend from friend list
- Any request to chosen social network - you got full SDK/API
Tutorial article on CodeProject
Adding library
1) Using Maven Central
Add dependency for chosen module, here example for all modules, you can choose one or two
dependencies {
...
compile 'com.github.asne:asne-facebook:0.3.1'
compile 'com.github.asne:asne-twitter:0.3.1'
compile 'com.github.asne:asne-googleplus:0.3.1'
compile 'com.github.asne:asne-linkedin:0.3.1'
compile 'com.github.asne:asne-instagram:0.3.1'
compile 'com.github.asne:asne-vk:0.3.1'
compile 'com.github.asne:asne-odnoklassniki:0.3.1'
...
}
2) Import module to your project
For example, in AndroidStudio you can add modules via Gradle:
- Copy social module to your project.
- In settings.gradle include
':ASNECore', ':socialNetworkModuleName'
- In build.gradle of your app (YOUR_PROJECT/app/build.gradle) add new dependencies:
compile project(':socialNetworkModuleName')
Without Gradle, add ASNE like:
- Open Project Settings and choose Modules.
- Find button "Add" (+), and choose Import module
- Find ASNECore and socialNetworkModuleName directories - «Add».
- Choose Create module from existing sources, then click "Next" rename module from "main" to "ASNECore".
- Add new asne-module in dependencies to your app.
Using library
Firstly, you need to create app in social network. You can read about main steps:
Second, we need to catch response after login via social network login dialog:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Fragment fragment = getSupportFragmentManager().findFragmentByTag(BaseDemoFragment.SOCIAL_NETWORK_TAG);
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
Then, you need to initialize mSocialNetworkManager
, it contain common interface for all ASNE social network modules. Initialize chosen social network and add social network to SocialNetworkManager(example: FacebookSocialNetwork):
mSocialNetworkManager = (SocialNetworkManager) getFragmentManager().findFragmentByTag(SOCIAL_NETWORK_TAG);
if (mSocialNetworkManager == null) {
mSocialNetworkManager = new SocialNetworkManager();
FacebookSocialNetwork fbNetwork = new FacebookSocialNetwork(this, fbScope);
//or from an activity
//FacebookSocialNetwork fbNetwork = new FacebookSocialNetwork(mSocialNetworkManager, this, fbScope);
mSocialNetworkManager.addSocialNetwork(fbNetwork);
getFragmentManager().beginTransaction().add(mSocialNetworkManager, SOCIAL_NETWORK_TAG).commit();
}
where fbScope
is permissions for your app, for example I used:
ArrayList<String> fbScope = new ArrayList<String>();
fbScope.addAll(Arrays.asList("public_profile, email, user_friends, user_location, user_birthday"));
Then you can send requests to social network like:
mSocialNetworkManager.getVKSocialNetwork().requestLogin(new OnLoginCompleteListener() {
@Override
public void onLoginSuccess(int socialNetworkID) {
}
@Override
public void onError(int socialNetworkID, String requestID, String errorMessage, Object data) {
}
});
Or get Social network directly like:
Session session = Session.getActiveSession();
Facebook Upgrades
Facebook some permissions you can get only after Facebook submission, so my demo app wasn't submitted due low functionality. So if you want to use it with all functionality send me your facebook id and I add you as tester - this is easy way to to fully use demo app email: [email protected]
Apps are no longer able to retrieve the full list of a user's friends (only those friends who have specifically authorized your app using the user_friends permission) but if you add me as friend you will see me in friendlist(profile)
ASNE developed on the basis of (Android Social Networks) mostly redone and add new features(some features are pulled to Android Social Networks)
Evgeny Gorbin - [email protected]
License ===================== ASNE is made available under the MIT license: [MIT license](http://opensource.org/licenses/MIT):The MIT License (MIT) Copyright (c) 2014 Evgrny Gorbin 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.