I'm doing an integration of my app with Linkedin, what happens is that I can perform the authentication and on return to Activity
of my app it would show me the data of the logged in user.
I'm using Linkedin APIs, but because I'm still starting development, I do not know where and how to call the method that retrieves the data, below my code.
Can you help me with this? I just want to know a way to get the first name and last name of the logged in user.
Thank you in advance.
package com.example.testeli;
import com.linkedin.platform.LISession;
import com.linkedin.platform.LISessionManager;
import com.linkedin.platform.errors.APIHelper;
import com.linkedin.platform.errors.LIApiError;
import com.linkedin.platform.errors.LIAuthError;
import com.linkedin.platform.listeners.ApiListener;
import com.linkedin.platform.listeners.ApiResponse;
import com.linkedin.platform.listeners.AuthListener;
import com.linkedin.platform.utils.Scope;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import com.example.testeli.R;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
final Activity thisActivity = this;
Button linkedin = (Button) findViewById(R.id.linkedin);
linkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LISessionManager.getInstance(getApplicationContext()).init(
thisActivity, buildScope(), new AuthListener() {
@Override
public void onAuthSuccess() {
// Authentication was successful. You can now do
// other calls with the SDK.
}
@Override
public void onAuthError(LIAuthError error) {
// Handle authentication errors
}
}, true);
}
});
}
// Build the list of member permissions our LinkedIn session requires
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.W_SHARE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Add this line to your existing onActivityResult() method
LISessionManager.getInstance(getApplicationContext()).onActivityResult(
this, requestCode, resultCode, data);
}
public void getProfile() {
String url = "https://api.linkedin.com/v1/people/~?format=json:(id,first-name,last-name)";
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest(this, url, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse s) {
onApiSuccess(s);
}
@Override
public void onApiError(LIApiError LIApiError) {
// TODO Auto-generated method stub
}
});
}
}