• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get URL of a image in sd card

 
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to get the URL of a image I have saved to a SD card/ external storage of device. I need the string of URL to pass to setPicture(string url) of facebook share dialog SDK so I can upload this image to FB from device.

So far have tried getting the URL from URI of a file path to string:

File imagePathFile = new File(savedImagePath);
try{
userImageURL = imagePathFile.toURI().toURL();
Log.d(TAG, "File URL for saved image on FB: " + userImageURL);
}catch(MalformedURLException ex)
{ //ex.printStackTrace();
}
userImageURLString = userImageURL.toString(); setPicture(userImageURLString)

//userImageURLString = "file:/storage/emulated/0/dive_photos/image4373.png";

But keep getting error:

(#100) picture url not properly formed

any input much appreciated.
Ciaran

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You share pictures that are already on the internet, you upload pictures that aren't. So you need to upload the picture from the phone to Facebook (via a Request call: https://developers.facebook.com/docs/reference/android/current/class/Request/). I am not sure you will need to share the image after that or not, but if you do need a separate share action then you could get the ID for the image you upload (provided in a callback) and then do the share dialog with the URL of the image (which will be "https://www.facebook.com/photo.php?fbid=" + photoID).
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Steve thanks allot, I've been at this for a couple weeks and was barking up the wrong tree till now.

So I have an idea how to post the image to the users photo album (I've read the method does this by default).
So I have two questions:
1. How do I pass a File to a Bundle which then needs to be passed to a Request object?
2. How do I get the URL of a image posted on the callback?

I have this code to date:

Request request = new Request();


And the call-back method:

 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ciaran Mooney wrote:So I have two questions:
1. How do I pass a File to a Bundle which then needs to be passed to a Request object?


You already have filled out the Request.newUploadPhotoRequest() parameters with the imagePathFile. That method fills in the parameters bundle for you, no need to add it yourself, just execute it.

Ciaran Mooney wrote:2. How do I get the URL of a image posted on the callback?


The callback gets a Response, the Response lets you get a GraphObject, and the GraphObject lets you get properties for the object just uploaded. The important property is "id" and you would add the result to the end of the URL I posted in the previous post. Something like this:
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
p.s. The SDK for Facebook's Android API is here: https://developers.facebook.com/docs/reference/android/current. In my experience it is poorly formatted and not well documented, but it is, at least, a place to look for what objects and methods are available.
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks again.

I am almost there, the photo will upload into a album specified in the file path, in the users profile BUT I cannot use the URL until the user manually accepts the photo in the photo album which kinda makes the exercise pointless...

Instead FB uses a really odd default blank to upload until the photo is accepted.



Looked around SDK (which i fns v awkward) and can't find anything.



Code to date is:

//open a session accord to FB share dialog instructions

//start a session
Session.openActiveSession(this, true, new Session.StatusCallback() {



@Override
public void call(final Session session, SessionState state, Exception exception) {
//callback when session changes state


 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Message i get on Facebook:

Would you like to add these photos to your album?
The photos below were uploaded from another application, you'll need to approve them.


 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure the answer to this one, I only played with it a tiny bit a while ago (before deciding I didn't want to contribute to the Facebook Spam). But this could be because you need to request more permissions to for your application (so the user gives permission on the phone rather than the site). Look here: https://developers.facebook.com/docs/android/login-with-facebook. The publish permissions are at the bottom.
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I finally got form the link you sent.




FB developers site is awful, I found it very hard to find info I was looking for.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome, glad you got it working! I agree, their site is not well organized and the documentation is not much more than re-starting the method name and parameter names. They could use a significant amount of re-work to explain what happens, required permissions, what the expected input is, what likely use-cases are, etc... The fact that references to other classes in their API are not hyperlinked is also a poor decision. We should take this into consideration when we write our documentation: do it better than FB!
 
Ciaran Mooney
Ranch Hand
Posts: 74
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't be too hard! I have a headache thinking about it........again thanks for your help couldn't of done it otherwise.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic