Now the code below is a mixture of two sketches. The goal here is that the user inputs a search term. Upon hitting enter the applet searches tinysong for the song and returns the song id (this works in its own sketch). The term is simultaneously searched for on twitter using the twitter4j library(this also works on its own.)
However when I put the two together i get the following error "jsonObject is ambiguous" ???????
for the purpose of this example I removed my api keys..
Any help would be awesome.
import controlP5.*;
//import java.net.*;
/////////////////////
ControlP5 controlP5;
controlP5.Label label;
Textfield myTextfield; /// setting up text-input field
int myBitFontIndex;
PFont p = createFont("Avenir",32);
///////////////////
/* TinySong API*/ // this is how you search the grooveshark database.
String tinyK = "";
int songIdNum;
String searchT; // the user inputs their query
String searchString;
ConfigurationBuilder cb = new ConfigurationBuilder();
Twitter twitterInstance;
Query queryForTwitter;
ArrayList tweets;
String[] userName = new String[0];
String[] tweetsArr = new String[0];
void setup(){
size(1024,640);
////////////////////
cb.setOAuthConsumerKey("");
cb.setOAuthConsumerSecret("");
cb.setOAuthAccessToken("");
cb.setOAuthAccessTokenSecret("");
twitterInstance = new TwitterFactory( cb.build() ).getInstance();
///////////////////
int txtFw = 440;
controlP5 = new ControlP5(this);
controlP5.setControlFont(p);
myTextfield = controlP5.addTextfield("enter a song name",(width/2)-(txtFw/2),(height/11)*2,txtFw,80);
myTextfield.setFocus(true);
//myTextfield.valueLabel().setFont(myBitFontIndex);
myTextfield.valueLabel().style().marginTop = -6;
////////////////////////////////////
}
void draw(){
background(0);
finTweets();
}
void keyPressed(){
if(key == ENTER || key == RETURN){
searchT = myTextfield.getText();
searchT = searchT.replaceAll(" ","+");
FetchTweets();
println(searchT);
searchString = "http://tinysong.com/b/"+searchT+"?format=json&key="+tinyK;
///////////////////
///////////////////
println(searchString);
try{
String url = searchString;
JSONObject wholeJson = new JSONObject(join(loadStrings(url),""));
JSONObject resp = wholeJson; // remove .getJSONObject(""); as this json file has no objects
songIdNum = resp.getInt("SongID");
// songIdNum = resp.getInt("m");
println("The song ID for "+searchT+" is: "+songIdNum);
}
catch(JSONException e){
println("there was an error parsing the JSONObject");
}
}
}
void FetchTweets(){
String twitQ = "#"+searchT;
queryForTwitter = new Query(twitQ);
try{
QueryResult result = twitterInstance.search(queryForTwitter);
tweets = (ArrayList) result.getTweets();
}
catch (TwitterException te){
println("couldn't connect this time" + te);
}//end catch
}//end function
void finTweets(){
for(int i=0; i<tweets.size(); i++){
Status t = (Status) tweets.get(i);
userName = append(userName, t.getUser().getScreenName());
tweetsArr = append(tweetsArr, t.getText());// adds tweets to array
//get geoLoc later
text(userName[i] + "said: " + tweetsArr[i],20,15+i*30,width-20,40);
}//end loop
}