As mentioned at the end of the class for Week 3, here is the link to the instructions for obtaining a Google Maps API key, which you will need to see the maps for the class next week.
<a href="http://code.google.c...is/mapkey.html" target="_blank">http://code.google.c...mapkey.html</a>
<a href="http://code.google.c...bugfingerprint" target="_blank">http://code.google.c...fingerprint</a>
<a href="http://code.google.c...pi-signup.html" target="_blank">http://code.google.c...signup.html</a>
Also, attached is an overview slide that gives you an idea of the steps involved.
I am a student in uni. hertfordshire. i was given a course work to write a twitter app for android enabled mobile phones. i got the online tutorial of tonny and it has helped me to this point but i've not been able to go pass week 1 step 3 for the past 2 weeks. I am using twitter4j 2.2.4. my program always stop at the Authorization blank page instead of bringing in twitter log in page as shown at the end of week 1 step 3. the codes that i used are below pls i need help on this. pls it's urgent. Thanks
package com.seyi.android.projecttwitter;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.auth.RequestToken;
import android.app.Application;
import twitter4j.TwitterFactory;
import com.seyi.android.projecttwitter.authorization.OAuthHelper;
public class MyProjectApplication extends Application {
private OAuthHelper oAuthHelper;
private RequestToken currentRequestToken;
private Twitter twitter;
@Override
public void onCreate() {
super.onCreate();
oAuthHelper = new OAuthHelper(this);
twitter = new TwitterFactory().getInstance();
oAuthHelper.configureOAuth(twitter);
}
public Twitter getTwitter(){
return twitter;
}
public boolean isAuthorized(){
return oAuthHelper.hasAccessToken();
}
public String beginAuthorization(){
try {
if (null == currentRequestToken){
currentRequestToken = twitter.getOAuthRequestToken();
}
return currentRequestToken.getAuthorizationURL();
}
catch (TwitterException e) {
e.printStackTrace();
}
return null;
}
}
package com.seyi.android.projecttwitter.activities;
import com.seyi.android.projecttwitter.MyProjectApplication;
import com.seyi.android.projecttwitter.R;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class AuthorizationActivity extends Activity {
private MyProjectApplication app;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = (MyProjectApplication)getApplication();
setContentView(R.layout.authorization_view);
setUpViews();
}
@Override
protected void onResume() {
super.onResume();
String authURL = app.beginAuthorization();
webView.loadUrl(authURL);
}
private void setUpViews() {
webView = (WebView)findViewById(R.id.web_view);
}
}
package com.seyi.android.projecttwitter.activities;
import com.seyi.android.projecttwitter.MyProjectApplication;
import com.seyi.android.projecttwitter.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
public class StatusListActivity extends ListActivity {
private MyProjectApplication app;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app =(MyProjectApplication)getApplication();
setContentView(R.layout.main);
}
@Override
protected void onResume() {
super.onResume();
if(!app.isAuthorized()){
beginAuthorization();
}
else{
// load the user's home timeline
}
}
private void beginAuthorization() {
Intent intent = new Intent (this , AuthorizationActivity.class);
startActivity(intent);
}
}
package com.seyi.android.projecttwitter.authorization;
import java.io.InputStream;
import java.util.Properties;
import twitter4j.Twitter;
import android.content.Context;
import com.seyi.android.projecttwitter.R;
public class OAuthHelper {
private String consumerKey;
private String consumerSecretKey;
private Context context;
public OAuthHelper (Context context){
this.context = context;
loadConsumerKeys();
}
public void configureOAuth(Twitter twitter){
twitter.setOAuthConsumer(consumerKey,consumerSecretKey);
}
public boolean hasAccessToken(){
return false;
}
private void loadConsumerKeys() {
try {
Properties props = new Properties();
InputStream stream = context.getResources().openRawResource(R.raw.oauth);
props.load(stream);
consumerKey = (String)props.get("consumer_key");
consumerSecretKey = (String)props.get("consumer_secret_key");
} catch (Exception e) {
throw new RuntimeException("Unable to load consumer keys from oauth.properties", e);
}
}
}
authorization_view.xml<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
http://schemas.andro...pk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/enter_pin_title"/>
</RelativeLayout>
main.xml<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
http://schemas.andro...pk/res/android" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@id/android:list"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@id/android:empty"
android:text="@string/no_tweets"
android:gravity="center_vertical|center_horizontal"/>
</RelativeLayout>
strings.xml<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="authorization">Authorization</string>
<string name="authorize">Authorize</string>
<string name="enter_pin">To authorize, sign in to Twitter and enter Pin here:</string>
<string name="no_tweets">tweets are not available now</string>
<string name="app_name">Project Twitter</string>
</resources>
oauth.properties fileconsumer_key=82Rdur4NgikjyxGXaVaA
consumer_secret_key=FuPg1qYJbZ8fy66OlBQuD4zJ981tFLvxWyMHYEYXQM