I followed this tutorial http://kodefun.junian.net/2011/10/easy-facebook-android-sdk-simple.html and managed to successfully connect to facebook.
But how do I get user photos? Here's the code so far:
...
public void loginSuccess(Facebook facebook) {
GraphApi graphApi = new GraphApi(facebook);
User user = new User();
try{
user = graphApi.getMyAccountInfo();
//update your status if logged in
graphApi.setStatus("Hello, world!");
} catch(EasyFacebookError e){
Log.d("TAG: ", e.toString());
}
fbLoginManager.displayToast("Hey, " + user.getFirst_name() + "! Login success!");
List<Photo> listPh = graphApi.getAllPhotosMy();
Photo ph = listPh.get(0);
/// ... how do I get a user photo to drawable or something?
}
...
Any ideas? :) Thanks!
Just from messing around in there reference, I would say you would get the persons's ID and the feed that into a from, and then feed that from into the photo again.
I'm no expert on this, but there documentation is your friend.
http://www.easyfacebookandroidsdk.com/doc/index.html
Related
I did a simple sign up user interface just to check parse but for some reason every time i try to register a user it gives me this error
this is the code:
final ProgressDialog dlg = new ProgressDialog(this);
dlg.setTitle("Please wait.");
dlg.setMessage("Signing up. Please wait.");
dlg.show();
String username_str = username.getText().toString();
String password_str = password.getText().toString();
String re_password_str = re_password.getText().toString();
String email_str = email.getText().toString();
String phone_str = phone.getText().toString();
if(!re_password_str.equals(password_str)){
dlg.dismiss();
Toast.makeText(this,"Passwords does not match!!",Toast.LENGTH_SHORT).show();
password.setText("");
re_password.setText("");
}else if(email_str.isEmpty()|| phone_str.isEmpty()){
dlg.dismiss();
Toast.makeText(this,"email or phone cannot be empty!!",Toast.LENGTH_SHORT).show();
}else {
ParseUser new_user = new ParseUser();
new_user.setUsername(username_str);
new_user.setPassword(password_str);
new_user.setEmail(email_str);
new_user.put("phone", phone_str);
new_user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
dlg.dismiss();
if(e == null){
Intent i = new Intent(SignupActivity.this,MainActivity.class);
startActivity(i);
}else{
Log.d("signup error", e.toString());
Toast.makeText(SignupActivity.this,e.toString(),Toast.LENGTH_SHORT).show();
}
}
});
I've already spent 2 days in finding the problem but without any success....
I have deleted manually some data from the Parse Database. After that I was having this error when I was trying to save a new user in background:
com.parse.ParseRequest$ParseRequestException: invalid session token
My solution was to uninstall the apk and install it again. It solved the session problem for me.
Important: I did this in the Debug Database, so uninstalling a Debug App and install it again was fine.
You might not have logged out from your previous session. Make sure you have a log out logic. Also check if any of your users have logged in before signing in or signing up another user.
The belog code might help,
var currentUser = Parse.User.current();
if (currentUser) {
// do stuff with the user
Parse.User.logOut();
}
Also don't forget to add e.preventDefault(); in your sign up function.
This is how I had my signUp function..
$('.form-signup').on('submit', function(e) {
var currentUser = Parse.User.current();
if (currentUser) {
// do stuff with the user
Parse.User.logOut();
}
e.preventDefault();
var user = new Parse.User();
var username = $('#username').val();
var password = $('#password').val();
var email = $('#email').val();
user.set("username", username);
user.set("password", password);
user.set("email", email);
user.signUp(null, {
success: function(user) {
//signup successfull
alert("user created..!! User name: "+ username);
window.location = "login.html";
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
console.log("Error: " + error.code + " " + error.message);
//alert("User not created..!! " + error.message);
$("H5").html("User not created..!! " +error.message);
}
});
});
The reason for this problem is that you may be testing another Parse application on the same virtual device so the user credentials are still used for the new application. So, the solution for this is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add this line and run your application
ParseUser.getCurrentUser().logOut();
It is due to data deletion from database but local storage still have that data. So you have to clear data from local storage.
Eg.
For Javascript (browser):
window.localStorage.clear()
For React Native:
AsyncStorage.clear();
For android:
Either clear cache or reinstall app
Yes I think after signing up a user you might have deleted that row from the users class, so first, write this code in your Activity
if(ParseUser.getCurrentUser()!=null){
Toast.makeText(this,"yes not null",Toast.LENGTH_SHORT).show();
ParseUser.logOut();
}
else{
Toast.makeText(this," null",Toast.LENGTH_SHORT).show();
}
You can find the difference when you run your app, first, it will toast you "yes not null" and after if you run your app again it will show you "null"
Now you can signup your user :)
This worked for me.
Hope it works for you as well.
You can find more info at.
It seems like a known bug in the Parse SDK. There is already a bug reported on the forum. They claim to have this fixed in the latest version 1.7.3. But it's not working for me either.
Refer to this https://developers.facebook.com/bugs/756392341145634/?search_id
I manually cleared the session and I had the same problem while trying to sign up a new user from the same device I signed up previously. Clearing the data for the App in DEVICE settings fixed the problem.
If you encounter this problem in your web app, clear the local storage of all Parse data. On Chrome this is:
Developer Tools (F12)
Application
Local Storage
Choose Parse entries and press Delete key (or Backspace)
I'm developing my first Android App using Parse and Facebook, so I'm pretty new to it.
I'm trying to retrieve the User's Friend List with Request.newMyFriendsRequest() but it gives me an empty list when testing with real users.
As far as I know, with Graph API v2.0 this request only will return the set of the person's friends who also use the app.
For that purpose I created a fake Fb profile, I became friend with him in Facebook with my real profile, installed my app, registered with ParseUser and Linked with Facebook using ParseFacebookUtils.link with both profiles, but the Request returns an empty list of friends.
I've created several Test Users in Facebook's App dashboard, and simulated several friendships between them. I made the same process in my app (register with parseUser, link with ParseFacebookUtils.link) with two of them, and the list users.size() returns 2 friends as expected.
Why it doesn't work with my actual profile and the fake one (which is like any other real one)??
This is how I'm linking profiles:
List<String> permissions = new ArrayList<String>();
permissions.add("public_profile");
permissions.add("user_friends");
ParseFacebookUtils.link(currentUser, permissions, MainActivity.this, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ParseFacebookUtils.isLinked(currentUser)) {
Log.d(TAG, "Woohoo, user logged in with Facebook!");
Toast.makeText(getApplicationContext(), "Facebook succesfully linked", Toast.LENGTH_LONG).show();
}
if (ex != null) {
Log.d (TAG, ex.getLocalizedMessage() + "\n + Exception Code: " + ex.getCode());
}
});
And this how I Request friends:
Request.newMyFriendsRequest(ParseFacebookUtils.getSession(), new GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
Log.d(TAG, "Request Completed!! " + response.toString() + "----" + users.size());
if (users != null) {
List<String> friendsList = new ArrayList<String>();
for (GraphUser user : users) {
friendsList.add(user.getId());
}
}
}
}).executeAsync();.
But I can't figure out how to get the friends list of a real user. With my profile it should return 1 friend who is also registered using the app being developed...
I got an empty array because of the following:
- This will only return any friends who have used (via Facebook Login) the app making the request.
Please note!
My application is very image centric and would like to allow the user to share images generated by the application on facebook posts. I am of the understanding that "User Generated" can only be used with user/camera taken photos so that is not an option. Correct?
Since I can't specify user generated, I'd like to either:
Set the link on the feed image such that the image in the album is opened, not the default og:url.
This link is by default the og:url specified in the open graph object.
I still need all of the other og:url links in the post except the image to point to the website page.
-OR-
Put an href link in the description (or somewhere else in the feed post) that opens the image in the album.
Unless I am mistaken, It doesn't seem that HTML href tags are allowed in posts/stories. Is there a way to do this in the caption of a custom story?
I am able to upload the image to the app's album and obtain the URL to the image in the album (also using "no story" so that it doesn't create a post).
Is what I'm trying to do possible?
How do I garner more control over the links set in a facebook feed post?
EDIT:
Regarding "User Generated" from facebook docs:
"The User Generated Photos action capability can only be used if the photos are original and taken by a user with an actual camera."
I don't want to generate two stories. Ideally I want ONE story that features an image that can be clicked on that links to the original full size image in the app album. The rest of the story shares some details about the image (desc. etc.). So I guess, in a way, I'm looking for a workaround for the camera/photo requirement.
I don't mind the standard story layout (with a smaller image with title, description/captions) but just want to link that image to one in the users application album.
EDIT:
I'm realizing that an Open Graph Story isn't the way to go here. I have instead gone to simply using the Graph API. (https://developers.facebook.com/docs/graph-api/reference/user/photos/) This allows me to post a link in the user comments along with a photo. For anyone interested:
public static void doImagePost(final Bitmap _sideBySide, String _comments) {
Bundle parameters = new Bundle();
parameters.putParcelable("image", _sideBySide);
String message;
if(_comments != null)
{
if(!_comments.isEmpty())
{
message = _comments + '\n' + '\n' + JSBridge.getURL();
} else {
message = JSBridge.getURL();
}
} else {
message = JSBridge.getURL();
}
//Plain Http://blahblahblah.com/foobar/whatever gets turned into a link in the message field
parameters.putString("message", message);
Bitmap redSideBySide = EHelper.reduceImageSize(_sideBySide, (int)4E6);
Session session = Session.getActiveSession();
if(session == null) {
requestPublish(MODE_PHOTO, redSideBySide, _comments);
return;
} else {
if(!session.isOpened())
{
requestPublish(MODE_PHOTO, redSideBySide, _comments);
return;
}
}
//Here is the Graph API request.
Request imagePostRequest = new Request(Session.getActiveSession(), "me/photos" , parameters, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
if(response.getError() == null)
{
Toast.makeText(m_Context, "Post image success", Toast.LENGTH_SHORT).show();
//m_Images = null;
dismissProgressDlg();
} else {
Toast.makeText(m_Context, "Error posting image to facebook: " + response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
Log.e(DEBUG_TAG, "Error posting image to facebook: " + response.getError().getErrorMessage());
dismissProgressDlg();
}
}
});
showProgressDialog("Posting to Facebook...");
imagePostRequest.executeAsync();
}
I'm trying to post my data through android app on my twitter account so how should i do it.
i have tried a way, below is the code, and in that it is showing the data on my account and i need to click on the tweet button to get it tweeted. So can i know how to post it directly without asking me to tweet. Like Four Square app
public void open(View view){
String text = "Share Your Experiance ....!!!";
String url = "twitter://post?message=";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url + Uri.encode(text)));
startActivity(i);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(this, "Can't send tweet! Please install twitter...", 2).show();
}
Thanks in Advance !!!
Firstly you have to check are you logged with twitter or not after as your condition you can apply this snippet code.
I think you follow the all basics for twitter integration in your code.
public void uploadPic(String message, String getImgUrl)
throws Exception {
try {
System.out.println(" ON UPLOAD PIC FUNCTION getImgUrl "+getImgUrl);
// URL url = new URL("http://faveplatewebservice.siplstudio.com/uploads/big_dish/oooo14n7464rO4_thumb.png");
URL url = new URL(getImgUrl);
URLConnection urlConnection = url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
StatusUpdate status = new StatusUpdate("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message);
//status.setMedia(file);
status.setMedia("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message, in);
mTwitter.updateStatus(status);
} catch (TwitterException e) {
Log.d("TAG", "Pic Upload error" + e.getExceptionCode());
throw e;
}
}
hope it will help you!!
If you stuck anywhere then inform me.
Thankss!!
i am developing and application in which i want to get some feeds from twitter like picture, name, tweets, time and number of reply on each tweet. i did all but could not get number of reply for each tweet.... help me out thanks in advance..
i am posting my code also.
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("BeingSalmanKhan",paging);
for (Status status3 : statuses)
{
TwitterFeeds tFeeds = new TwitterFeeds();
System.out.println(status3.getText());
tFeeds.strTweet = status3.getText();
tFeeds.strDate = status3.getCreatedAt().toString();
System.out.println("---------------------------------- " + status3.getSource());
al_tweets.add(tFeeds);
}
str_tw_name = unauthenticatedTwitter.showUser("BeingSalmanKhan").getName();
str_tw_imgurl = unauthenticatedTwitter.showUser("BeingSalmanKhan").getProfileImageURL().toString();
bitmap_twpic = NewsActivity.DownloadImage(str_tw_imgurl);
Try this snippet of code... it worked for me.. hope for you too
try {
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
//URLEntity[] uent=
//First param of Paging() is the page number, second is the number per page (this is capped around 200 I think.
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("ashabhosle",paging);
System.out.println("status no 2 ="+statuses.get(2).toString());
long retweetcnt=statuses.get(2).getRetweetCount();
System.out.println("retweet count on 2nd tweet "+retweetcnt);
for (Status status3 : statuses)
{
System.out.println(status3.getText());
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to get timeline: " + e.getMessage());
}
try getRelatedResults(),gives a list of replies + mentions,it is the closest to getting replies.