I am trying to integrate Facebook sdk into my app.
When I press facebook login button, it shows generic erro "An error occurred. Please try again later"
Anyone knows what might be the cause of it.
private final class ButtonOnClickListener implements OnClickListener {
public void onClick(View arg0) {
if (mFb.isSessionValid()) {
SessionEvents.onLogoutBegin();
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFb);
asyncRunner.logout(getContext(), new LogoutRequestListener());
} else {
mFb.authorize(mActivity, mPermissions, new LoginDialogListener());
}
}
}
Can anyone help me with this issue?
Thanks a lot.
Make sure you use your app id while running the application.
Try EasyFacebookAndroidSDK, it's easy to implement. here is a good sample http://kodefun.junian.net/2011/10/easy-facebook-android-sdk-simple.html
Related
I am in the middle of learning Spring WebFlux. I am using a REST call using below code to parse the response:
private void parseJsonResponse(String folderId) throws IOException {
Mono<ObjectNode> theresponseMono = webClient.get()
.uri("/some/uri")
.retrieve().bodyToMono(ObjectNode.class);
ObjectNode node = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.readValue(theresponseMono.share().block().toString(), ObjectNode.class);
//handle node object here.....
}
Question: Is theresponseMono.share().block() non-blocking here? If not, what can be done to make is completely non-blocking. I am looking for the relevant documentation on this as I want to learn it and not just looking for a yes or no. To summarize, I need to retrieve theresponseMono as non-blocking. Any guidance or any official documentation/link on this please? Thanks.
EDIT:
This is what I am trying to achieve:
Mono<ObjectNode> theresponseMono = webClient.get()
.uri("/some/uri")
.retrieve().bodyToMono(ObjectNode.class).flatMap(node -> {
if (node.get("list").get("entries").isArray()) {
for (JsonNode jsonNode : node.get("list").get("entries")) {
System.out.println(jsonNode);
}
}
});
Somehow I am not able to map using flatMap. What is missing here?
No since here you are blocking it. Right way would be to do
private Mono<ObjectNode> parseJsonResponse(String folderId) {
return webClient.get()
.uri("/some/rui")
.retrieve().bodyToMono(ObjectNode.class)
.flatMap(node-> {
// do your logic here
})
}
I would say everything what is in mono/flux must stay in mono/flux :) Anytime you call block its blocking your thread.
I am very new to both java and vaadin. Hope to be able to get some good tips on how I can improve my code.
I would like to rewrite the code below to use Vaadin´s -> LoginOverlay instead of the code below.
As I said, I'm trying to learn so I have used the code for this example: https://www.youtube.com/watch?v=oMKks5AjaSQ&t=1158s
However, LoginOverlay seems to be a better way to display its login part through. As in this example: https://www.youtube.com/watch?v=pteip-kZm4M
So my question is how can you write the code below as a LoginOverlay.
public class LoginView extends Div {
public LoginView(AuthService authService) {
setId("login-view");
var username = new TextField("Username");
var password = new PasswordField("Password");
add(
new H1("Welcome"),
username,
password,
new Button("Login", event -> {
try {
authService.authenticate(username.getValue(), password.getValue());
UI.getCurrent().navigate("home");
} catch (AuthService.AuthException e) {
Notification.show("Wrong credentials.");
}
}),
new RouterLink("Register", RegisterView.class)
);
}
}
I have only come this far to convert the code.
A clarification of the new part of the code. The code does not work. The part with loginOverlay.addLoginListener (event -> probably needs to be written in a different way.
I'm using IntelliJ 2020.3.4 if that is of any help.
public class LoginView2 extends Composite<LoginOverlay> {
public LoginView2(AuthService authService) {
setId("login-view");
LoginOverlay loginOverlay = getContent();
loginOverlay.setTitle("Welcom");
loginOverlay.setDescription("Manage your business tasks");
loginOverlay.setOpened(true);
loginOverlay.addLoginListener(event -> {try {
if(authService.authenticate(username.getValue(), password.getValue());
UI.getCurrent().navigate("home");
} catch (AuthService.AuthException e) {
Notification.show("Wrong credentials.");
}
}),
new RouterLink("Register", RegisterView.class);
}
}
}
}
Super grateful for all the help you can give.
Many thanks to everyone who makes stackoverflow so amazing.
Copy-pasting code snippets with little idea about what the code does is a recipe for disaster, especially when it comes to security.
You have all kinds of errors in your code: misplaced braces, using variables that do not exist, and a RouterLink far from where it belongs.
I understand you've got to start somewhere. I would recommend starting from code that actually compiles, and then gradually adding things, testing what you have so far at every step.
Here are some tips for your LoginView2:
Remove the whole loginOverlay.addLoginListener(...) code, including the authService.authenticate call and the RouterLink. Make sure that you can run the application at this point, and that you can see the login overlay.
Add back the login listener, but for now just show a notification in it. Test that you can run the application, and that if you click Login, your notification is displayed.
loginOverlay.addLoginListener(event -> {
Notification.show("This is working");
});
Implement the authentication. You have a call to authService.authenticate(...) inside an if-statement, but the method does not return anything. Instead, it throws an exception if the authentication fails, hence the try-catch. This means that inside the try { ... } block, any code you put after the authService.authenticate(...) call is only executed if it did not throw an exception, i.e. if the authentication was successful.
There are no username or password variables. The first YouTube video had defined these variables in the form of text fields. With the login overlay, it creates those fields for you, so how do you get the corresponding values from it?
I'm trying to test for file chooser availability. I assumed an error would be returned if none was available, however, this is not the case.
Here's my code:
public void doImport() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select a File to Import"), IMPORT_RACES_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Utils.Error(this, "THERE WAS NO NAVIGATOR FOUND, Install a navigator!");
} catch (Exception e) {
Utils.Error(this, "Some other error occurred!");
}
}
No Exception is being sent back to my routine, though. The OS seems to be handling the error and generating a dialog box stating "No apps can perform this action."
Any idea what I'm doing wrong here?
Thanks!
Actually, found the answer in this thread:
Android : Can I use this intent from a 3rd party application?
See the "isIntentAvailable" routine posted by the responder.
Thanks, all!
I have a very strange beaviour in my game.
First of all, I have two version: paid and free, linked in same play service ID.
I developed and try the apps, and they work perfectly, so I put them in production, on google play.
Then I discover by feedback that the paid version, when accept the invitation, don't handle, becouse it's null!
In the free version instead, it works fine.
THE CODE IS THE SAME.
How is possible?
The same APK installed manually works, then put on google play doesn't works.
Anyone has this problem?
This is the code:
#Override
public void onSignInSucceeded() {
super.onSignInSucceeded();
Log.i(GameProps.TAG, "invitation: "+getInvitationId());
if (getInvitationId()!=null) {
Intent intent=new Intent(this, OnlineGameScreen.class);
intent.putExtra(GameProps.INVITATION_ID, getInvitationId());
startActivity(intent);
}
}
getInvitationId() return null.
How it is possibile?
Bye.
I solved.
The code before is changed with this:
#Override
public void onSignInSucceeded() {
super.onSignInSucceeded();
getGamesClient().loadInvitations(new OnInvitationsLoadedListener() {
#Override
public void onInvitationsLoaded(int statusCode, InvitationBuffer buffer) {
ArrayList<Long> timestamps=new ArrayList<Long>();
for (Invitation invitation:buffer) {
timestamps.add(invitation.getCreationTimestamp());
}
Collections.sort(timestamps);
if (!timestamps.isEmpty()) {
for (Invitation invitation:buffer) {
Log.i(GameProps.TAG, "invitation buffer: "+invitation.getInvitationId());
if (invitation.getCreationTimestamp()==timestamps.get(timestamps.size()-1)) {
invitationId=invitation.getInvitationId();
}
}
}
Log.i(GameProps.TAG, "invitation: "+invitationId);
if (invitationId!=null) {
Intent intent=new Intent(MainScreen.this, OnlineGameScreen.class);
intent.putExtra(GameProps.INVITATION_ID, invitationId);
startActivity(intent);
}
}
});
}
So I have to say that GooglePlayGames lib is buggy, becouse getInvitationId() doesn't work correctly.
Expecially becouse it works if apk is installed manually, and not for app downloaded from playstore.
It's happend with 2 of 4 of my apps, so I think it will remain a mistery.
How to use getAllOpenedActivities(), getActivityMonitor(), setActivityOrientation(), getButton(); getCurrentButton(), methods? I'am new for Robotium even i dont know how to use any get method, Please anyone help me to explain with example. It'll more helpful for me.
Thanks in Advance.
To use any of the methods, you need to create a Solo object. Like this:
#Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
Then in your test method you call the method:
public void testYourTest() throws IOException{
solo.clickOnText("Menu");
solo.getButton("Button 1");
etc.
}
I would recommend that you reference the javadoc that Robotium provides. It was included in the file you downloaded as a .jar file. You need to change the extension (.jar) to zip (.zip).
Hope this helps!