I am using simple facebbok to integrate facebook to my application.i need to send the facebook username to server.but i got the username as null from profile listner.
here is my code
public void loginToFacebook(View v){
mSimpleFacebook.login(this);
}
OnLoginListener listner = new OnLoginListener() {
#Override
public void onLogin() {
mSimpleFacebook.getProfile(onProfileListener);
}
};
OnProfileListener onProfileListener = new OnProfileListener() {
#Override
public void onComplete(Profile profile) {
System.out.println(profile.getUsername());//getting null here
}
};
I have also tried with the code,
OnLoginListener listner = new OnLoginListener() {
#Override
public void onLogin() {
Profile.Properties properties = new Profile.Properties.Builder()
.add(Properties.USER_NAME)
.add(Properties.ID)
.build();
mSimpleFacebook.getProfile(properties, onProfileListener);
}
};
But the listner is not getting fired in this case.
This is the permission i have given in the Application class
private void configureFacebook() {
Permission[] permissions = new Permission[] {
Permission.USER_ABOUT_ME,
Permission.PUBLIC_PROFILE,
Permission.READ_STREAM,
Permission.EMAIL,
Permission.PUBLISH_ACTION
};
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
.setAppId(Constants.FB_APPID)
.setNamespace("namespace")
.setPermissions(permissions)
.build();
SimpleFacebook.setConfiguration(configuration);
}
You can't get username in API v2.0
Related
I tried implementing a signIn method from the OneDrive API, but I am not sure I correctly understood the workflow.
Basically, on first launch of the app, I want to have both the login window and the "authorise the app to..." window". But then, when the user launches the app again, I would like to be directly connected to the app, without any window.
Instead, with the following code, I keep having the second window (where the user decides to accept the app)
#Override
public void signIn() {
//personal code
linkingStarted = true;
signInStatus = SignInStatus.SIGNING_IN;
activity.setUpWait(R.layout.popup_waitgif_white);
//end of personal code
mAuthClient = AuthClientFactory.getAuthClient(activity.getApplication());
if (mAuthClient.getSession().isExpired() && Util.isConnectedToInternet(activity)) {
activity.alertOnUIThread("Login again");
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
mAuthClient.login(activity, SCOPES, mAuthListener);
}
});
} else if (!Util.isConnectedToInternet(activity)) {
activity.alertOnUIThread(activity.getString(R.string.alert_verifyconnection));
} else {
activity.alertOnUIThread("Resigned In OneDrive");
signInStatus = SignInStatus.SIGNED_IN;
mAuthClient.initialize(SCOPES, new AuthListener() {
#Override
public void onAuthComplete(final AuthStatus status, final AuthSession session, final Object userState) {
if (status == AuthStatus.CONNECTED) {
authToken = session.getAccessToken();
oneDriveService = getOneDriveService();
signInStatus = SignInStatus.SIGNED_IN;
} else {
authenticationFailure();
Log.v(TAG, "Problem connecting");
}
}
#Override
public void onAuthError(final AuthException exception, final Object userState) {
//mAuthClient.login(activity, SCOPES, mAuthListener);
}
}, null, authToken);
}
}
and the AuthClientFactory is just this:
public class AuthClientFactory {
private static AuthClient authClient;
private static final String CLIENT_ID = "00000000XXXXX";
public static AuthClient getAuthClient(Context context) {
if (authClient == null)
authClient = new AuthClient(context, OneDriveOAuthConfig.getInstance(), CLIENT_ID);
return authClient;
}
}
You would have an easier time with the OneDrive SDK for Android, as authentication is a much simpler process.
final MSAAuthenticator msaAuthenticator = new MSAAuthenticator() {
#Override
public String getClientId() {
return "<msa-client-id>";
}
#Override
public String[] getScopes() {
return new String[] { "onedrive.appfolder", "wl.offline_access"};
}
}
final IClientConfig oneDriveConfig = new DefaultClientConfig.createWithAuthenticator(msaAuthenticator);
final IOneDriveClient oneDriveClient = new OneDriveClient
.Builder()
.fromConfig(oneDriveConfig)
.loginAndBuildClient(getActivity());
That will take care of the user authentication flow and then give you a service object that makes interacting with OneDrive straight-forward. See the full example application.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I having some issue in creating a dialog of type group in quickblox chat service on android. I am able to get all the user from the server side of quickblox, able to build dialog and adding those users i got in it but when it comes to call groupChatManager.createDialog(dialog, new QBEntityCallbackImpl(). I am getting a null pointer exception on that. I found later that i have to initialise chatService in class that extends application i did that but still same error. here is my code
enter code here
My applicationSingeltonClass
public class ApplicationSingleton extends Application
{
private QBUser currentUser;
//quickBlox
private static final String APP_ID = "key";
private static final String AUTH_KEY = "authkey";
private static final String AUTH_SECRET = "authsec";
private static ApplicationSingleton instance;
private Map<Integer, QBUser> dialogsUsers = new HashMap<Integer, QBUser>();
private QBRoomChat currentRoom;
#Override
public void onCreate()
{
super.onCreate();
initApplication();
initImageLoader(getApplicationContext());
}
public static ApplicationSingleton getInstance()
{
return instance;
}
private void initImageLoader(Context context)
{
// This configuration tuning is custom. You can tune every option, you may tune some of them,
// or you can create default configuration by
// ImageLoaderConfiguration.createDefault(this);
// method.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.enableLogging() // Not necessary in common
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
public QBUser getCurrentUser()
{
return currentUser;
}
public void setCurrentUser(QBUser currentUser)
{
this.currentUser = currentUser;
}
public Map<Integer, QBUser> getDialogsUsers()
{
return dialogsUsers;
}
public void setDialogsUsers(List<QBUser> setUsers)
{
dialogsUsers.clear();
for (QBUser user : setUsers)
{
dialogsUsers.put(user.getId(), user);
}
}
public void addDialogsUsers(List<QBUser> newUsers)
{
for (QBUser user : newUsers)
{
dialogsUsers.put(user.getId(), user);
}
}
public Integer getOpponentIDForPrivateDialog(QBDialog dialog)
{
Integer opponentID = -1;
for(Integer userID : dialog.getOccupants())
{
if(userID != getCurrentUser().getId())
{
opponentID = userID;
break;
}
}
return opponentID;
}
private void initApplication()
{
instance = this;
QBChatService.setDebugEnabled(true);
QBSettings.getInstance().fastConfigInit(APP_ID, AUTH_KEY,AUTH_SECRET);
}
}
here is my other class were i create a dialog
enter code here
protected void onPostExecute(final Boolean success)
{
if(status.equals("accepted"))
{
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(10);
final ArrayList<String> usersLogins = new ArrayList<String>();
usersLogins.add(userID);
usersLogins.add(herocivID);
final ArrayList<Integer> occupantIdsList = new ArrayList<Integer>();
occupantIdsList.add(civID);
occupantIdsList.add(heroCivID);
QBUsers.getUsersByFacebookId(usersLogins, pagedRequestBuilder, new QBEntityCallbackImpl<ArrayList<QBUser>>() {
#Override
public void onSuccess(ArrayList<QBUser> users, Bundle params)
{
if (!QBChatService.isInitialized())
{
QBChatService.init(getApplicationContext());
chatService = QBChatService.getInstance();
chatService.addConnectionListener(chatConnectionListener);
}
QBDialog dialog = new QBDialog();
dialog.setName("chat with mostafa wo may");
dialog.setType(QBDialogType.GROUP);
dialog.setOccupantsIds(occupantIdsList);
QBGroupChatManager groupChatManager = chatService.getInstance().getGroupChatManager();
groupChatManager.createDialog(dialog, new QBEntityCallbackImpl<QBDialog>()
{
#Override
public void onSuccess(QBDialog dialog, Bundle args)
{
Log.i("", "dialog: " + dialog);
}
#Override
public void onError(List<String> errors) {
Toast.makeText(getBaseContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onError(List<String> errors)
{
Toast.makeText(getBaseContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
}
});
Toast.makeText(getBaseContext(), "you accepted the request", Toast.LENGTH_SHORT).show();
}
else if(status.equals("rejected"))
{
Toast.makeText(getBaseContext(), "you rejected the request", Toast.LENGTH_SHORT).show();
}
}
i need to know were exactly i have to configure the chat service to prevent the null pointer while creating a dialog.
Any help would be appreciated thank you.
You're right,
chatService.getInstance().getGroupChatManager();
is null if you're not logged in ti Chat
so you have to login to chat first and then call this method
I managed to solve this issue.
First you need to check roomChatManager if its equal to null you have to ask the user to login in.
Second in the login wether your using social provider or by mail you have to login to chatService ( ApplicationSingleton.getInstance().chatService.login(userResult);)
ApplicationSingleton is a java class were it extends Application in it you initialise the ChatService.
Thats it now you can create your dialog successfully.
When I use HTC Android, it do very well. However, when I use API of Facebook to login using Samsung Android 4.2, I show an Toast message like "login fail please contact the marker of this app and ask them to issue 1732910 to facebook"
Please help me to fix it!
public class FacebookLogin {
/* variable Facebook */
private static final String FACEBOOK_APPID = "578073962236765";
private FacebookConnector facebookConnector;
private final Handler mFacebookHandler = new Handler();
ActivityBase activity;
Request.GraphUserCallback userCallback;
LoginService.OnSwimLogedInEvents swimLoginCallBack;
LoginService loginService;
Dialog changeDialog;
LoadingDialog loadingDialog;
public FacebookLogin(ActivityBase activity, Request.GraphUserCallback userCallback, LoginService.OnSwimLogedInEvents swimLoginCallBack) {
this.activity = activity;
this.loadingDialog = new LoadingDialog();
this.userCallback = userCallback;
this.swimLoginCallBack = swimLoginCallBack;
this.loginService = new LoginService(activity);
this.facebookConnector = new FacebookConnector(FACEBOOK_APPID,
activity, activity, new String[]{
"publish_stream", "email", "user_birthday", "read_stream", "offline_access"});
}
public void login() {
Session.initializeStaticContext(activity);
if (facebookConnector.getFacebook().isSessionValid()) {
facebookConnector.getFacebook().getSession()
.closeAndClearTokenInformation();
}
AuthListener listener = new AuthListener() {
#Override
public void onAuthSucceed() {
doLogin();
}
#Override
public void onAuthFail(String error) {
//(new MessageAlert()).showDialog("Facebook authetication fail\r\nError:" + error, activity);
}
};
SessionEvents.addAuthListener(listener);
facebookConnector.login();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data);
}
private void doLogin() {
AsyncTaskBase<Void, Void, Void> t = new AsyncTaskBase<Void, Void, Void>(
activity) {
#Override
protected Void doInBackground(Void... params) {
mFacebookHandler.post(facebookUserInfoRunner);
return super.doInBackground(params);
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
};
t.execute();
}
final Runnable facebookUserInfoRunner = new Runnable() {
#Override
public void run() {
loadingDialog.showDialogLoading(activity);
Request.executeMeRequestAsync(facebookConnector.getFacebook()
.getSession(), new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
SwimAccount currentAccount = ((SwimApp) activity.getApplication()).getCurrentAccount();
currentAccount.setAvatarUrl("https://graph.facebook.com/" + user.getId() + "/picture");
currentAccount.setIsLogin(true);
currentAccount.setFirstName(user.getFirstName());
currentAccount.setLastName(user.getLastName());
currentAccount.setStringId(user.getId());
currentAccount.setAccountType("facebook");
currentAccount.setEmail((String) response.getGraphObject().getProperty("email"));
currentAccount.setBirthdate(user.getBirthday());
currentAccount.setGender((String) response.getGraphObject().getProperty("gender"));
if (userCallback != null) {
userCallback.onCompleted(user, response);
}
loginService.login(currentAccount.getEmail(), "", currentAccount.getAccountType(), currentAccount.getStringId(), swimLoginCallBack);
//changeDialog.dismiss();
}
});
}
};
}
Found a solution to my problem. Try deleting the android:noHistory="true" from the Facebook login activity in your manifest. This messes with the authentication flow of the Session.
It looks like people on XDA have had this same problem.
They are claiming that you can try either of these:
(1) "Don't keep activities" option on Settings > Developer Options. If it's ON, then when an app calls some popup, system closes app, so then system restarts it ... and there got your loop.
(2) If you uninstall the Facebook App, you can then login through your app, and then re-install the Facebook app.
Not sure how "official" these answers are, but thought it might be worth a shot to you.
Sources:
http://forum.xda-developers.com/showthread.php?p=43200939 and http://forum.xda-developers.com/showthread.php?t=2186035
I'm trying to get the Salesforce REST API working with Android and new to android programming, followed the sample code to connect with SFDC http://wiki.developerforce.com/page/Getting_Started_with_the_Mobile_SDK_for_Android#Authentication
I'm trying to get a few records from SFDC and display them in the android app, looks like when the Async Call is made at "client.sendAsync(sfRequest, new AsyncRequestCallback()" - NullPointerException is thrown.
I did see a couple of similar issues online, but didn't help me. Hoping if some one would point me in the right direction to troubleshoot this. Thanks much.
public class GetAccountsActivity extends Activity {
private PasscodeManager passcodeManager;
private String soql;
private String apiVersion;
private RestClient client;
private TextView resultText;
private RestRequest sfRequest;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get Api Version
apiVersion = getString(R.string.api_version);
//Create Query
soql = "select id, name from Account limit 10";
// Setup view
setContentView(R.layout.get_accounts_activity);
((TextView) findViewById(R.id.Acc_Title)).setText(apiVersion);
// Passcode manager
passcodeManager = ForceApp.APP.getPasscodeManager();
}
#Override
public void onResume() {
super.onResume();
//Get SFClient
// Login options
String accountType = ForceApp.APP.getAccountType();
LoginOptions loginOptions = new LoginOptions(
null, // login host is chosen by user through the server picker
ForceApp.APP.getPasscodeHash(),
getString(R.string.oauth_callback_url),
getString(R.string.oauth_client_id),
new String[] {"api"});
new ClientManager(this, accountType, loginOptions).getRestClient(this, new RestClientCallback() {
#Override
public void authenticatedRestClient(RestClient client) {
if (client == null) {
ForceApp.APP.logout(GetAccountsActivity.this);
return;
}
GetAccountsActivity.this.client = client;
}
});
//Get Rest Object to query
try {
sfRequest = RestRequest.getRequestForQuery(apiVersion, soql);
//Use SF Rest Client to send the request
client.sendAsync(sfRequest, new AsyncRequestCallback(){
#Override
public void onSuccess(RestRequest request, RestResponse response){
//Check responses and display results
// EventsObservable.get().notifyEvent(EventType.RenditionComplete);
}//end onSuccess
#Override
public void onError(Exception exception) {
//printException(exception);
EventsObservable.get().notifyEvent(EventType.RenditionComplete);
}//End Exception for Async Method
});
}catch (UnsupportedEncodingException e) {
//printHeader("Could Send Query request");
//printException(e);
return;
}
}
}
enter code here
You are calling client.sendAsync from onResume() but client is not set until the authenticatedRestClient callback is called, you need to move your sendAsync call into the authenticatedRestClient callback.
how do I share my comments to facebook using socialize, I tried the following codes but it directly enters into the facebook home page its not sharing my comments...can anyone help me
here is my code,
public class TraSocializeActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String entityKey = "http://www.getsocialize.com";
Entity entity = Entity.newInstance(entityKey, "Socialize");
View actionBarWrapped = Socialize.getSocializeUI().showActionBar(this, R.layout.main, entity);
setContentView(actionBarWrapped);
//this is the code for sharing my comments to facebook but its not working it allows the //user to enter the facebook directly
if(Socialize.getSocialize().isAuthenticated()) {
//Entity entity1 = Entity.newInstance("http://someurl.com", "My Entity");
String comment = "The comment to be added";
ShareOptions options = new ShareOptions();
options.setShareLocation(true);
options.setShareTo(SocialNetwork.FACEBOOK);
options.setListener(new SocialNetworkListener()
{
public void onError(Activity activity, SocialNetwork network, String message, Throwable e)
{
}
public void onBeforePost(Activity activity, SocialNetwork network)
{
}
{ // Handle before post
}
public void onAfterPost(Activity activity, SocialNetwork network)
{ // Handle after post
}
});
Socialize.getSocialize().addComment(this, entity, comment, options, new CommentAddListener()
{
public void onError(SocializeException error) {
// Handle error
}
public void onCreate(Comment comment)
{ // Handle success
}
});
}
}
}
I'll ping our devs to get you an answer tonight. Sorry for the delay; just saw your question. - DROdio