I can't load images from Graph Facebook - android

url: https://graph.facebook.com/100779423975829/picture?type=large;
other url with type normal: https://graph.facebook.com/100779423975829/picture?type=normal
I tried to load url with Glide, Picasso, UniversalImageLoader and decodeStream from BitmapFactory and don't have any good result and the result is the next:
UniversalImageLoader: Image can't be decoded
BitmapFactory: bitmap = null
If I open the url with Chrome pc I will automatically download the photo without opening it.
in the webview from my app, i check the redirects from this url:
https://lookaside.facebook.com/platform/profilepic/?asid=100779423975829&height=200&width=200
https://m.facebook.com/platform/profilepic/?asid=100779423975829&height=200&width=200
Anyone else is having problems loading image profiles from Facebook graphs?
Thanks!
EDIT
The bug is resolved from Facebook.
https://developers.facebook.com/bugs/261587761048160/

Finally this was a facebook bug. So the problem is fixed by themselves.
https://developers.facebook.com/bugs/261587761048160/

Yes, the redirections from http:// to https:// protocols hinders the downloading using Picasso,Glide ets. You may go ahead with following two approaches:
SimpleDraweeView from Facebook Sdk. It handles the redirection internally.
Make a graph request to fetch the re-directed url like below and use that url in picasso.
new GraphRequest(AccessToken.getCurrentAccessToken(),
"/"+fbUserId+"/picture?width="+width+"&height="+height+"&redirect=false",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
String url = response.getJSONObject().getJSONObject("data").getString("url");
loadFacebookProfilePicInImageView(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
).executeAsync();

I have the same issue. If you don't want to use the graph api for loading the public profile picture (as in my case) we both have a problem unless someone knows the solution.

I have the same problem. It seems to be a bug. I think we are best of just waiting a day or two instead of putting the effort in fixing this ourselves. See also : Facebook graph user picture won't show on mobile devices and https://developers.facebook.com/bugs/560392384345729/

Related

displaying an image from drive in Android

I'm using Fresco library to display images in my Android app. I'd like to display some images (jpg or png) that I have set with public grants.
When I was doing quick tests, I just took any image from internet to set a URL, but when using the real ones that I need to use, I have the following url https://drive.google.com/uc?export=view&id=<>, but as it is a redirect and, once redirected, new url is not the image itself, Fresco is unable to display it.
I have tried Picasso as an alternative library, but with out any success.
I have also tried the download url for both libraries (https://drive.google.com/uc?export=download&id=<>). But no result.
Anybody knows how could it be possible to get this images? Or the only solution is to download it (using the second url) processing the object received store a bitmap of it and displaying it?
For downloading it, what should i use and how? retrofit?
Thanks in advance.
Fresco supports different network stacks. For example, you can use OkHttp with Fresco, which should follow redirects or modify the default one to allow redirects - or write your own based on them.
Guide for OkHttp: http://frescolib.org/docs/using-other-network-layers.html
Related GitHub issue: https://github.com/facebook/fresco/issues/61
I found a solution for this problem (but could be only applicable if you use Google Cloud or Google Script).
It consists on creating a doGet() service with the following code inside:
var file = DriveApp.getFileById(fileId)
return Utilities.base64Encode(file.getBlob().getBytes());
and use that base64 value in your app. With this format, Fresco can do the magic
It is not an immediate solution, and requires to do somework in other platform that is not your Android app, but it works perfectly.
Are you sure that there is no problems with your URLs?
Picasso works with direct URLs like: https://kudago.com/media/images/place/06/66/06662fda6309ce1ee9116d13bd1c66d5.jpg
Then you can download your image like:
Picasso.with(this)
.load(url)
.noFade()
.placeholder(R.drawable.placeholder_grey) //if you want to use a stub
.into(imageView, new com.squareup.picasso.Callback() {
#Override
public void onSuccess() {
//here you can operate with image after it is downloaded
}
#Override
public void onError() {
}
});
Hope it will help you.

How to detect a redirection in Glide v4 / OkHttp3?

Using Glide v4 and OkHttp3, how can I detect a redirection and load another url when it happens?
My usecase: I use the Glide v4 library with OkHttp3 to download pictures in my app. Sometimes when a picture is not available, a redirection is performed by the server to provide another picture instead of the one I originaly wanted. I can see it in my browser because when I request url A, I finally land on url B with the second picture. When that happens I want to instead load url C that is derived from url A (so not a static url).
At the moment I can detect the redirection using an OkHttp3 Interceptor:
public Response intercept(#NonNull Chain chain) throws IOException {
String requestUrl = chain.request().url().toString();
Response response = chain.proceed(chain.request());
String responseUrl = response.request().url().toString();
boolean redirect = !requestUrl.equals(responseUrl);
if (redirect) {
Timber.d("Detected redirection");
}
return response;
}
but then I don't know how to cleanly load url C. I don't see how I can load another url in the interceptor, and if I throw an IOException to handle the error later in a Glide RequestListener it will just result in a GlideException so I can't determine why it was throw.
OkHttp should be automatically redirecting by default and loading the final content. See OkHttpClient.Builder.followRedirects.
https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html#followRedirects-boolean-
My own testing suggests this is working, e.g.
$ oksocial 'https://httpbin.org/redirect-to?url=https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg'
For detecting it, I assume your interceptor is registered via addInterceptor instead of addNetworkInterceptor. Is that correct?
It is also worth ensuring the redirect is via a 30X response and not via a HTML refresh.
The solution I ended up with is pretty ugly: the request interceptor I showed in the question raise an IOException when a redirection is detected. I will then use a GlideListener to detect the error, and load the url C. The ugly part is that in the GlideListener I can't determine the cause of the error, it can be a redirection but it can also be a network error or anything else.
A cleaner version of this solution can probably be achieved with a custom OkHttpUrlLoader but it's too much code for my simple usecase.
This is my solution in Glide v4 / OkHttp3
String redirect = response.header("location");
if(redirect != null && !request.url().toString().equals(redirect)) {
// if redirected your code here
}

Using uri (android.net.uri) as a link to get image from internet and put it in a ImageView

I have a item object, containing a Uri variable called image. something like this
http://icons.iconarchive.com/icons/designcontest/vintage/256/Type-icon.png
I tried to get from the class method the Uri and use it for setting up the ImageView called Image in my viewholder
viewHolder.Image.setImageURI(item.getImage());
but it didn't work, so I tried something more complex without success
//Image
URL url = null;
try {
url = new URL(item.getImage().toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
viewHolder.Image.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
I have allowed internet permissions, and if I use some images from local with Uri.parse it works without any problem.
Here's the error I get from logcat
E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.net.URLConnection java.net.URL.openConnection()' on a null object reference
I think the problem is something in the url definiton but I'll ask you if someone had my same problem and how you solved. Thanks in advance!
for this purpose try to use a specific image library like Picasso, Glide or Fresco. The first one is the simplest with nice fluent interface and it loads images pretty fast:
Please check it, as you may don't know it. Here is a short description taken from its official site (link below):
Images add much-needed context and visual flair to Android
applications. Picasso allows for hassle-free image loading in your
application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Many common pitfalls of image loading on Android are handled
automatically by Picasso:
Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.
From: http://square.github.io/picasso/
As it already Open Source project you can check the code to improve it or make your own version fitted to your actual needs.
Hope it help
In all likelihood, url = new URL(item.getImage().toString()); is throwing a MalformedURLException, which your catch block is suppressing. As a result, url is null, which is why you're getting a NullPointerException. A constructor can't return a null, so this is the only thing I can imagine.
Unless you really know what you're doing, I recommend you use a library like Glide to do image fetching.

Picasso library stopped working today with facebook graph picture links

In my app i use Picasso library to load images from urls.
It is a nicely working easily importable and usable library, and just do the thing i need.
However, today it stopped working, and not while developping it is stopped working on a compiled apk.
So after i searched and searched for the reason i just found this buggy thing:
I use facebook graph urls to load profile pictures.
Here is one like:
profile pictre,
the link is actually "http://graph.facebook.com/1464090949/picture?type=large"
But it is redirecting to:
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg
Of course, both of url calls working in a browser, and you can see the profile picture.
However when i test both links with Picasso:
ImageView iv = (ImageView)findViewById(R.id.imageView1);
//Url1 NOT working, loads nothing.
String url1 = "http://graph.facebook.com/1464090949/picture?type=large";
//Url2 is the same as URL1, i just copied it from a browser, and this is working
String url2 = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg";
Picasso.with(this).load(url2).into(iv);
So the conclusion is, facebook maybe changed something and from now on Picasso cannot load images from graph.
Anybody can suggest me something to make this work?
Of course i can try different libraries but if there is an other way i would be really happy.
Workaround1:
Change to https from http.
Working:
https://graph.facebook.com/1464090949/picture?type=large
Not Working:
http://graph.facebook.com/1464090949/picture?type=large
Workaround2:
Found soulution on this topic.
If you want for example:
http://graph.facebook.com/1464090949/picture?type=large
This profile picture you could use:
https://graph.facebook.com/1464090949/?fields=picture.type(large)
Which returns a JSON Object:
{
"id": "1464090949",
"picture": {
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg",
"is_silhouette": false
}
}
}
And tada! There it is. url's key is the redirected url you can use to load your images.
(This will need oAuth which i didnt tested, just stick with Workaround1)
Try this. worked for me perfectly
Dependency: compile 'com.squareup.okhttp:okhttp:2.5.0'
Picasso.Builder builder = new Picasso.Builder(mContext);
builder.listener(new Picasso.Listener() {
#Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
/*holder.getIvSpeakerPicture()
.setImageDrawable(context.getResources()
.getDrawable("your drawable id"));*/
}
});
builder.downloader(new OkHttpDownloader(mContext));
builder.build().load(image).into(viewHolder.image);
In case you're using Amazon AWS CloudFront just like me, you can visit this page for detailed instructions from Amazon on how to set up your URL forwarding.
At the least, for Picasso to work with your redirected URLs, your URLs must support https. That is. https://yourdomain.com should redirect to https://yourAWScloudfrontdomain.net
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/SecureConnections.html#CNAMEsAndHTTPS

Flickr-Android API : Oauth is not redirecting to 'grant-access' page

I'm developing an Android application which requires Flickr API integration. In previous days, I was able to successfully complete the oauth process. But now its not working, and I strongly believe it happend after flickr APIs changed from http:// to https://
Let me explain the situation..
I'm following the steps explained in Flickr API Doc
As a result of the call to http://www.flickr.com/services/oauth/request_token API, I'm successfully receiving the oauth_token.
After this step, I'm presenting Flickr authorization page in a webview with the url specified in API doc (which is somthing similar like, https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432, and of-course, with the oauth_token which I received in the previous step)
Few days before this call was working when I'm using http:// instead of https://. But now, both http:// and https:// are not working. The page is displaying the login screen, but after successful login, the page is not redirecting to the grant access page, instead it is just redirecting to the Flickr Home page. And hence, I'm unable to grant access and unable to receive the oauth_verifier.
Hope I'm well explaining the situation which I'm facing now. But in short, Flickr Login for my application is not working, and I'm running out of time... :(
So, Geeks, Please give some light on the issue...
--Thanks in advance.
I got the same problem. I was using the connection in a WebView and my code was using the "http" protocol in the request.
I could resolve the issue by first using the "https" protocol for the authentification URL. As you say just doing that did not work. So I change the call of the url that was in the WebView and used the ACTION_VIEW intent and it worked.
Calling :
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(AuthentificationPath)));
Don't forget to implement the OnResume() function of your Activity to get the data of the returned intent.
Of course it is just a workaround but it does the job if you have to be fast.
Hope it helps!
Still the issue is there, After oauth Flickr is not redirecting to grant_access page. But I need to get the oauth process successfully completed in my on-going project, as soon as possible. So I have done a workaround to solve the issue.
To solve the 'not redirecting' issue, I have done a little bit change in my WebView's WebViewClient implementation. It's nothing great, but just redirecting to authorize page again, after successful login.
Authorize URL Example : https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432
So, given below is the detailed implementation of WebViewClient:
mAuthWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
showProgressDialog();
/** TODO: This part should be deleted after flickr fixes the oauth redirection issue */
if(url.endsWith("flickr.com/")) {
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
return;
}
/* After successful login the redirected url will contain a parameter named 'oauth_verifier' */
if (url.indexOf("oauth_verifier=") > -1) {
/* Get the 'oauth_verifier' parameter from url and do next steps */
performLoginSuccess();
}
}
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (url.contains(_my_redirect_url_) && !url.contains("oauth_verifier=")) {
/* User not authenticated our app */
finish();
} else if (!url.contains("oauth_verifier=")) {
killProgressDialog();
}
}
});
After loading the authorization url, the web view will take the user to login page, and after user successfully loged into Flickr, with web vew client implementation we are again loading the authorization url, to present the grant access page.
mAuthWebView.loadUrl("https://www.flickr.com/services/oauth/authorize?oauth_token=72157626737672178-022bbd2f4c2f3432");
I know, this is not the right way to do this...
Any better solutions are always welcome.... :)

Categories

Resources