Setting Permissions To Access Cloud Storage From App Engine
Creating Twitter Access Credentials
Integrating Twitter access to your application is fairly simple. But before you write a single line of code, you need OAuth access credentials to log into Twitter. Here’s how to get those credentials.
First, go to https://dev.twitter.com/apps. You’ll see the following screen:
Click on Create Application, then fill in the application details boxes in the next screen:
Scroll all the way down and click the button marked Create Application.
After that, go to the Settings tab of your new application:
Go down to the Application Type section:
Click on the “Read, Write and Access direct messages” option, and save your settings.
Go back to the details tab:
Scroll down and press the button marked “Create my access token”:
After a moment, you’ll see entries for the OAuth consumer key, consumer secret, access token, and access token secret (they’ll look like long strings of random characters). These tokens can be passed to twitter4j or another Twitter library to log into Twitter.
Uploading And Serving Files With The Blobstore In Java
An Introduction To The Datastore In Java
Deadline exceeded while waiting for HTTP response from URL
Serving URL For Images Stored In Cloud Storage
Writing Files To Google Cloud Storage
Writing a file to Google Cloud Storage is easy in Java. All you need is the Google Cloud Storage library.
The following code writes a file into GCS. Bucket represents the name of the Cloud Storage bucket, object represents the filename, mime represents the MIME type, and data represents a byte array with the contents of the file you’re writing.
String bucket = "your_bucket_name";
String object = "file_name_here_including_extension";
GcsFilename gcs_filename = new GcsFilename(bucket, object);
//File Options
GcsFileOptions.Builder options_builder = new GcsFileOptions.Builder();
options_builder = options_builder.mimeType(mime);
GcsFileOptions options = options_builder.build();
GcsOutputChannel output = GcsServiceFactory.createGcsService().createOrReplace(gcs_filename, options);
output.write(ByteBuffer.wrap(data));
output.close();
Remember to set bucket permissions in Google Cloud Storage so your app can access the files.