Setting profile image from google cloud storage bucket in android - android

I am using google cloud storage for storing profile images for one of the android app which we are developing. I am able to store images to the cloud properly..I want to set the same image to imageview in my application using picasso API.
It is saying Access denied, When I share Image on cloud publicly, it is setting image to Imageview, otherwise not...
How could I give these public share through android application for user to set images using Picasso?
Thank you in advance

When you upload the image you must make sure (assuming you don't want authentication) the ACL is set to publicRead.
The upload in java looks like this:
storage.objects()
.insert(BUCKET_NAME, null, content)
.setName(fileName)
.setPredefinedAcl("publicRead")
.setKey(API_KEY)
.execute();
For setting the ACL manually in the developers console tick the "shared publicly" check box.
The url then looks like this:
http://storage.googleapis.com//
Good luck.

Related

Firebase storage URL keeps changing with new token

I'm trying to build a social media application using firebase database and storage. Below is the flow expected.
User upload a profile picture which is stored on firebase storage in the current user folder and the URL stored in firebase database for quick access. (Works fine)
User post their thoughts. This save users info such as post message, username and profile image URL in databases. (Works fine).
Problem
The problem now is say a user updates he's or her profile picture, this overrides the older profile image in firebase storage (in order manage storage and to make user image be the same across all comments and post). On the post message activity the older profile image URL can't be accessed cause the token as changed.
Question
I will like to know how this can be fixed in such that the firebase storage URL will be static (that is the same) accross all updates.
NB
Using Picasso and not firebase method to get the images
Although this question had been asked for a very long time, but I noticed some people still find it difficult solving this, so I will be providing my solution below.
STEP 1
Since storage URL are always dynamic (i.e the posses token) when changed, what I did was to use generic name for image file stored say avatar for all users
STEP 2
Create a directory in storage for each user as follows: users/{uid}/avatar.jpg
STEP 3
Pull or display the image by using the path in step 2 (see below)
ANDROID
StorageReference storageReference = FirebaseStorage.getInstance().getReference("users").child(userId).child("avatar.jpg");
Glide.with(context).using(new FirebaseImageLoader()).load(storageReference).diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.ch_white_icon).placeholder(R.drawable.ch_white_icon).into(imageView);
WEB
var storage = firebase.storage();
var pathReference = storage.ref('users/' + userId + '/avatar.jpg');
pathReference.getDownloadURL().then(function (url) {
$("#large-avatar").attr('src', url);
}).catch(function (error) {
// Handle any errors
});
With this you don't have to worry with the dynamic link anymore, whenever you upload a new image to the above path, it overrides the previous one and the code in step 3 will give you the new image.
PS: For Android Don't forget to change DiskCacheStrategy.ALL to DiskCacheStrategy.NONE if you don't want glide to cache image or you can use timestamp to get new image if cache is allowed.
Since the URL image is stored in the database, you could use a Cloud Function to update the value after a user has updated his picture.
You can trigger a Cloud function in response to the updating of files in Cloud Storage, see:
https://firebase.google.com/docs/functions/gcp-storage-events
You will find examples of Cloud Functions at: https://github.com/firebase/functions-samples
and the full doc at: https://firebase.google.com/docs/functions/

Instagram Basic Info without AccessToken

Can I get Instagram Full Name and Profile picture without Access Token. It seems I can't find any API for that.
I tried with:
https://www.instagram.com/{username}/media
But, I get only media if user has pictures and if user is public.
I found some android apps get Full Name and profile picture only with Username, I need something like that in my application.
I was trying to do similar kind of thing last month but Actually there are no official APIs for that ,
there is this website https://openinstagram.com idk how those guys crated this APIs but you can try this:
https://api.openinstagram.com/{username}
and replace the text username with any real username and you will get profile picture and full name of that user even if the user is private,
this is not the only example, there are multiple website running on same kinda thing website like web.stagram and websta and it's mentioned on there website that they aren't certified by Instagram (because they are using unofficial APIs)
hope this would help.

addOnfailurelistener being called when I try uploading an image to firebase storage

pic2I am new to firebase storage and I am trying to upload an image to firebase just so I could learn it. My app has a button. When I click on it. Image gets displayed on image view. The image gets displayed correctly, but that image is not stored to firebase storage. I have added the necessary code (OnClickListener of buttonpic1) from firebase website to upload that image to storage. But the image isnt uploaded and addOnfailurelistener gets called (I am using a toast in this method). Can anybody let me know why it is not being uploaded on firebase?
Firebase needs Google Play Services version 9.4.0 or newer in order to work, as explained here, so try to update it and check again.
Also, check if you have specified the appropriate rules for your Firebase Project. By default, Firebase Storage allows only authenticated users, but you can change it to public.
Go to the "Rules" tab of the "Storage" section in the console, and replace the code you see by that:
service firebase.storage {
match /b/your-bucket-id.appspot.com/o {
match /{allPaths=**} {
allow read, write;
}
}
}
where your-bucket-id put the address shown in the "Files" tab in the console (without gs://).

Flickr Integration within android app

I have uploaded some pics in "photostream" though the Flickr website.
Now I want to integrate Flickr in my Android app. How can I download those same pics in my device using the Flickr API? I did the "login" part for these but I don't know how to fetch my uploaded images.
flickr.people.getPhotos or flickr.people.getPublicPhotos
Return photos from the given user's photostream. Only photos visible to the calling user will be returned. This method must be authenticated; to return public photos for a user, use flickr.people.getPublicPhotos.
Note that the API docs lists this project https://code.google.com/p/flickrj-android/ which might make your life easier. In there it is the LoadPhotostreamTask.

Get the Google profile picture in Android

Is it possible currently to get the Google profile picture and paint it in an ImageView? I've been looking for posts that talk about this but I have not managed to find it.
geting google plus profile pic without using google api key
http://picasaweb.google.com/data/entry/api/user/any_name?alt=json
and after that you can grab img url in json and remove 's64-c' part from the url and
append "?sz=100" parameter (100 or lager size)
http://lh6.ggpht.com/-gAabIEudGQw/AAAAAAAAAAI/AAAAAAAAAAA/n062zUtBx4k/s64-c/101417311204099987701.jpg
I think what you need to do is authenticate and use one of the Google+ OAuth scopes (I think it would be plus.login), to get the profile picture url: https://developers.google.com/+/api/oauth#scopes
You can use the GoogleApiClient for this. Have a look into the documentation. Or take a look into the link in the comments of your question
https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html
After that you can use a library like Picasso to load the image from the URL into the ImageView: http://square.github.io/picasso/
Picasso.with(context).load(pictureUrl).into(imageView);

Categories

Resources