i have added facebook to my android app to share images and now the thing is that sharing can be done only from my facebook account, whenever i try and login from another account i cannot post any image this is the code snippet that i use . any help is appreciated
`
Request uploadRequest = Request.newUploadPhotoRequest(
Session.getActiveSession(), bmp, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast.makeText(FacebookUpload.this,
"Photo uploaded successfully",
Toast.LENGTH_LONG).show();
`
there is a part lyk this
`public void postImage() {
if (checkPermissions()) {
Bitmap bmp = null;
String filename = getIntent().getStringExtra("image");
try {
FileInputStream is = this.openFileInput(filename);
bmp = BitmapFactory.decodeStream(is);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
Request uploadRequest = Request.newUploadPhotoRequest(
Session.getActiveSession(), bmp, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast.makeText(FacebookUpload.this,
"Photo uploaded successfully",
Toast.LENGTH_LONG).show();
File dir = getFilesDir();
File file = new File(dir, "bitmap.png");
file.delete();
}
});
// post on user's wall.
Bundle params =uploadRequest.getParameters();
Random rand = new Random();
int rndInt = rand.nextInt(3)+1;
if(rndInt==1)
params.putString("name", "download Chummi-Lalli Mobile App from https://play.google.com/store/apps/details?id=com.interactive8.readmestories");
else if(rndInt==2)
params.putString("name","Send gifts to your loved ones from www.ekhudol.com");
else if(rndInt==3)
params.putString("name","Chummilalli brought to you by www.3leafsolutions.co.in");
else
params.putString("name","Chummilalli brought to you by www.3leafsolutions.co.in");
uploadRequest.setParameters(params);
uploadRequest.executeAsync();
}
else
requestPermissions();
}`
n whenever i use another account i my code always goes to this else part requestPermission(), why am i redirected here always, everything works fine when i use my own facebook account
it was really simple, i had to do nothing but just submit my app to fb, i didnt know about this step on the developer website, i figured it out and now my app works just fine, thanks though
i have multiple places where my app should upload files to Dropbox. when i try to upload a file the app is falling back to browser. if i use the DropboxApi object globally it says DropboxUnlinkedException.
I am posting my code
Dropbox.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// We create a new AuthSession so that we can use the Dropbox API.
AndroidAuthSession session = buildSession();
AJ_Constant.mApi = new DropboxAPI<AndroidAuthSession>(session);
// Basic Android widgets
// setContentView(R.layout.main);
if (mLoggedIn) {
logOut();
} else {
// Start the remote authentication
AJ_Constant.mApi.getSession().startAuthentication(DropBox.this);
}
}
#Override
protected void onResume() {
super.onResume();
if (session.authenticationSuccessful()) {
try {
// Mandatory call to complete the auth
session.finishAuthentication();
// Store it locally in our app for later use
TokenPair tokens = session.getAccessTokenPair();
storeKeys(tokens.key, tokens.secret);
} catch (IllegalStateException e) {
showToast("Couldn't authenticate with Dropbox:"
+ e.getLocalizedMessage());
Log.i(TAG, "Error authenticating", e);
}
}
}
The code for uploading file is :
(this code is in another file _someX.java)
com.dropbox.client2.DropboxAPI.Entry response = AJ_Constant.mApi.putFile(
AJ_Constant.ReportfileName, inputStream, file.length(),
null, null);
Should i re-build the session or get authentication process done everytime??
Please suggest me any solution
Thanks in advance
From the Android SDK docs (note the last line of code):
A typical authentication flow when no user access token pair is saved
is as follows:
AndroidAuthSession session = new AndroidAuthSession(myAppKeys, myAccessType);
// When user wants to link to Dropbox, within an activity:
session.startOAuth2Authentication(this);
// When user returns to your activity, after authentication:
if (session.authenticationSuccessful()) {
try {
session.finishAuthentication();
AccessTokenPair tokens = session.getAccessTokenPair();
// Store tokens.key, tokens.secret somewhere
} catch (IllegalStateException e) {
// Error handling
}
}
When a user returns to your app and you have tokens stored, just
create a new session with them:
AndroidAuthSession session = new AndroidAuthSession(
myAppKeys, myAccessType, new AccessTokenPair(storedAccessKey, storedAccessSecret));
i am stuck in Twitter integration.I am done with image uploading through url but i am not able to upload audio or video url to twitter.
Any help is appreciated. Thanx guys
Twitter Code for uploading youtube url:
twitter.updateStatus("This is My Youtube url Test http://youtu.be/pfHxl46KyZM");
Logcat:
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=12c480e1
TwitterException{exceptionCode=[b2b52c28-12c480e1], statusCode=403, message=Error creating status., code=189, retryAfter=-1, rateLimitStatus=null, version=3.0.6-SNAPSHOT}
String tweetUrl = "https://twitter.com/intent/tweet?text=Put your Audio URL here &url="
+ "https://www.google.com&hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
OR
// Consumer
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
// Access Token
AccessToken accessToken = null;
accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_SECRET);
twitter.setOAuthAccessToken(accessToken);
// Posting Status
Status status = null;
try {
status = twitter.updateStatus("YOUR_AUDIO_LINK");
} catch (TwitterException e) {
e.printStackTrace();
}
System.out.println("Successfully updated the URL: "
+ status.getText());
You cannot upload video directly to Twitter - they simply don't support it.
Follow these steps.
1.Upload the video to a 3rd party service (like YouTube)
2.Get the public URL of the uploaded video
3.Add the URL to the status you send to Twitter - e.g. "Look at my Birtday video http://youtube.com/id"
If you want, you can add a thumbnail of the video as an image attachment
Hope this is what you are looking for.
Note sure but check if this helps you:-
String videoPath="video file path";
TwitterSession twitterSession = new TwitterSession(MainActivity.this);
AccessToken accessToken = twitterSession.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(accessToken.getToken())
.setOAuthTokenSecret(accessToken.getTokenSecret()).build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file = new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder().setFile(file)
.setChunkSize(10485760).setMessage("Twitvid test")
.setPostToTwitter(true).create();
try {
if (helper.upload(twitvidPost)) {
Toast.makeText(MainActivity.this, "Posted on Twitter and Twitvid" ,Toast.LENGTH_LONG).show();
Log.d("MainActivity", "Posted on Twitter and Twitvid");
} else {
Toast.makeText(MainActivity.this, "Post failed", Toast.LENGTH_LONG)
.show();
Log.d("MainActivity", "Posted failed");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
GOAL
In my camera app i want to let user share a picture with pre-formatted text and a description on the user's facebook wall.
INTRO
I Googled a lot and followed "the terrific" facebook-getting-started, trying many things, for !!days!!... no completely working solutions found yet.
At least i think i got some points:
The great Android Intent action_send works great but not choosing facebook, that works for text OR for pictures, not for both (!!), see here
applicationID, hashxxx, and everything else needed to link android app to facebook login, all things that i really don't understand and don't want to, done and at last working (thanx facebook for all this sh*t!!)
share with facebook can be done (see here):
3a. using the facebook app (installed in the device)
3b. using a login session (if facebook app is not installed)
Facebook wants us to use its SDK, it's very [b|s]ad, but i can stand it.
case 3a - facebook suggests us to use the shareDialog, and -fighting a lot with code snippets and samples suggested!- i have been able to do it, but i need it to work also if facebook app is not installed (case 3b.)
case 3b - facebook suggests to use the "ugly" feedDialog as a fallback (see here).
6a. feedDialog needs login and it's ok...
6b. it seems feedDialog cannot share local images, i really don't understand why... here facebook guide talks only about "URL" for the "picture" keyword...
5c. then i think i must use Request, i tried implementing it but nothing happened, i think i'm missing something... No useful references (=working examples) found.
CODE SNIPPETS copy/paste/edit from SO and developers.facebook
ShareDialog and session management in case facebook app is not installed IT'S WORKING
/**
* share image with facebook, using facebook sdk
* #param pathToImage
*/
private void shareWithFacebook(String pathToImage) {
Log.i("SHARE", "share with facebook");
if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
Log.i("SHARE", "share with ShareDialog");
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
.setCaption("Sharing photo taken with MyApp.")
.setName("Snail Camera Photo")
.setPicture("file://"+pathToImage)
.setLink("http://myapplink")
.setDescription("Image taken with MyApp for Android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
// maybe no facebook app installed, trying an alternative
// here i think i need a session
if (Session.getActiveSession() != null && Session.getActiveSession().isOpened()) {
publishFeedDialog(pathToImage);
} else {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
List<String> permissions = new ArrayList<String>();
permissions.add("publish_actions");
session.openForRead(new Session.OpenRequest(this)
.setPermissions(permissions)
.setCallback(mFacebookCallback));
} else {
Session.openActiveSession(this, true, mFacebookCallback);
}
}
}
}
private Session.StatusCallback mFacebookCallback = new Session.StatusCallback() {
public void call(final Session session, final SessionState state, final Exception exception) {
if (state.isOpened()) {
String facebookToken = session.getAccessToken();
Log.i("SHARE", facebookToken);
Request.newMeRequest(session, new Request.GraphUserCallback() {
public void onCompleted(GraphUser user, com.facebook.Response response) {
publishFeedDialog(MP.LAST_TAKEN_FOR_GALLERY);
}
}).executeAsync();
}
}
};
feedDialog snippet, works for text fields, links, and remote url, but DOESN'T WORK FOR LOCAL PICTURES using "file://..." nor "file:///...". Error message: picture URL is not properly formatted.
private void publishFeedDialog(String pathToImage) {
Bundle params = new Bundle();
params.putString("name", "myapp Photo");
params.putString("caption", "Sharing photo taken with myapp.");
params.putString("description", "Image taken with myapp for Android");
params.putString("link", "http://myapp.at.playstore");
params.putString("picture", "file://"+pathToImage);
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(EnhancedCameraPreviewActivity.this,//getApplicationContext(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
public void onComplete(Bundle values,
FacebookException error) {
Log.i("SHARE", "feedDialog.onComplete");
if (error == null) {
// story is posted
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
Another try, using Request, it says:
photo upload problem. Error={HttpStatus: 403, errorCode: 200,
errorType: OAuthException, errorMessage: (#200) Requires extended
permission: publish_actions}
I tried adding publish_actions permission in the session management above, maybe i miss something...
private void publishFeedDialog(String pathToImage) {
Request request=Request.newPostOpenGraphObjectRequest(
Session.getActiveSession(),
"PhotoUpload",
"myApp Photo Upload",
"file://"+pathToImage,
"http://myapp.at.playstore",
"Image taken with myApp for Android",
null,
uploadPhotoRequestCallback);
request.executeAsync();
}
Last try with Request, absolutely nothing happens, both with or without "picture" keyword.
private void publishFeedDialog(String pathToImage) {
Bundle parameters = new Bundle();
parameters.putString("message", "Image taken with myApp for Android");
parameters.putString("picture", "file://"+pathToImage);
parameters.putString("caption", "myApp Photo");
Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, null);
// also tried: Request request = new Request(Session.getActiveSession(), "/me/feed", parameters, com.facebook.HttpMethod.POST);
request.executeAsync();
}
QUESTIONS
-1- Are there some faults in my 1..6 points?
-2- Can i share a local picture using FeedDialog?
-3- if not, how to when facebook app is not installed?
Thanks a lot!
I have the same problem, but I have a workaround.
I can't find any wrong reasoning in your point 1-6, look like the same issues I've come acrossed.
You can't share pictures locally, but...
Code snippet below:
This will upload the picture to the users profile and post it on his\hers wall, afterwhich you can get the URL if needed:
private void uploadPicture(final String message, Session session) {
Request.Callback uploadPhotoRequestCallback = new Request.Callback() {
#Override
public void onCompleted(com.facebook.Response response) {
if (response.getError() != null) {
Toast.makeText(getActivity(), "Failed posting on the Wall", Toast.LENGTH_LONG).show();
return;
}
Object graphResponse = response.getGraphObject().getProperty("id");
if (graphResponse == null || !(graphResponse instanceof String) ||
TextUtils.isEmpty((String) graphResponse)) {
Toast.makeText(getActivity(), "Failed uploading the photo\no respons", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), "Succsefully posted on the facebook Wall", Toast.LENGTH_LONG).show();
}
}
};
// Execute the request with the image and appropriate message
Request request = Request.newUploadPhotoRequest(session, profileBitmap, uploadPhotoRequestCallback);
Bundle params = request.getParameters();
params.putString("message", message);
request.executeAsync();
}
And to start facebook login when you don't have the APP, it's simpler, I use the following code snippet for calling the facebook SDK on facebook button:
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.faceBookButton:
if (((imagePath != null && !imagePath.equals("")) || (message != null && !message.equals("")))) {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForPublish(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("public_profile", "publish_actions"))
.setCallback(statusCallback));
} else {
if (profileBitmap != null) {
uploadPicture(message, session);
} else {
publishFeedDialog(message);
}
}
} else {
Toast.makeText(getActivity(), getString(R.string.checkin_fail), Toast.LENGTH_SHORT).show();
}
break;
}
}
In my case publishFeedDialog accepts the message you want to pass on, and not the image, but it doesn't matter. It opens up Facebook's message dialog anyway to which I haven't yet found a way to pass a predefined message from my EditText widget.
I am making an application in which i want to post videos on facebook.While i try to do that,i am getting this error:
Facebook Error: (#100) Requires extended permission: video_upload or Requires extended permission: publish_actions
This is the code:
mUploadButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
byte[] data = null;
AssetFileDescriptor fileDesc = getResources().openRawResourceFd(
R.raw.movie);
String dataPath = fileDesc.toString();
String dataMsg = "Your video description here.";
String dataName = "movie.mp4";
Bundle param;
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
InputStream is ;
try
{
is = fileDesc.createInputStream();
// is = new FileInputStream(dataPath);
if(is != null)
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putString("filename", dataName);
param.putByteArray("video", data);
mAsyncRunner.request("me/videos", param, "POST", new SampleRequestListener(), null);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
});
Please tell me what is the problem and how to solve it.
The problem is contained in the error message. It is a fairly clear error message I think.
In the Authentication flow for your app, you have not requested that the user grant you the video_upload, publish_actions or publish_stream Permission - any of those three will allow video uploads, but the third is more wide-ranging and triggers a second page on the auth dialog.
Check whichever SDK you're using to see if it has a convenient wrapper to ask for additional permissions in the auth flow. In the regular Oauth flow, you just add the list of permissions needed as the scope parameter in your call to the Oauth dialog