Hey All Twitter Developers,

I am having some trouble adding a place and I am honestly at a loss to
figure out what could be causing it. I always have to be careful when
asking for help to make sure I dont include any tokens. This is a
twitter4j example, but I am pretty sure this is a twitter API issue,
because I have a token that I get from getSimilarPlaces and I test
that its not null prior to add.

{"errors":[{"code":39,"message":"Creation token is missing or invalid
-- call similar_places to get a valid creation token"}]}

If anyone can see where I am tripping up, or thinks this may be bug
your input is appreciated, otherwise I hope this pretty complete
example helps someone.

BTW if you have an android phone and a twitter account I would love
you to
participate in our private beta! We are launching ratecred
internationally.

Thanks!
=================
Clay Graham
Starter
Sightly Inc.
http://sightlyinc.com
http://ratecred.com

====

package com.sightlyinc.twitter4j;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import twitter4j.GeoLocation;
import twitter4j.GeoQuery;
import twitter4j.Place;
import twitter4j.ResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.http.AccessToken;

public class AddPlace {
        static Logger logger =
                Logger.getLogger(AddPlace.class);
/*
 * @param args
 */
        public static void main(String[] args) {

                String userToken = args[0];
                String userTokenSecret = args[1];

                String consumerToken = args[2];
                String consumerTokenSecret = args[3];

                //GeoQuery{location=GeoLocation{latitude=37.801120999999995,
longitude=-122.274004}, ip='null', accuracy='null',
containedWithin='null', granularity='poi', query='null', name='Liege',
maxResults=5}
                GeoLocation location = new
GeoLocation(37.801120999999995d,-122.274004d);

                GeoQuery query = new GeoQuery(location);
                query.maxResults(5);
                query.granularity("poi");
                query.setName("Liege");
                logger.debug(query.toString());
                ResponseList<Place> response = null;

                try {
                        AccessToken accessToken = new AccessToken(
                                        userToken,
                                        userTokenSecret);
                        System.setProperty("twitter4j.debug", "true");
                        Twitter twitter =
                                new TwitterFactory().getOAuthAuthorizedInstance(
                                                consumerToken,
                                                consumerTokenSecret, 
accessToken);


                        response = twitter.getSimilarPlaces(query);
                        int position = 0;
                        for (Place place : response) {

                                GeoLocation loc = 
place.getBoundingBoxCoordinates()[0][0];

                                logger.debug("place:"+place.getName()+
                                                " phone:"+place.getPhone()+
                                                " geo:"+loc.getLatitude()+
                                                ","+loc.getLongitude());
                                position++;
                        }

                        //we have a token, use it to add the place
                        if(response.getToken() != null)
                        {
                                String containedWithin = "07d909e260dd3887";
                                query.setName("Liege Spirits Lounge");
                                logger.debug( "name:"+query.getName());
                                logger.debug( 
"containedWithin:"+containedWithin);
                                logger.debug( 
"addPlaceToken:"+response.getToken());
                                logger.debug( 
"lat:"+query.getLocation().getLatitude());
                                logger.debug( 
"lon:"+query.getLocation().getLongitude());

                                String address = "481 9th Street";

                                Map<String,String> attributes = new 
HashMap<String,String>();
                                if(address != null && address.length()>0)
                                        attributes.put("street_address", 
address);

                                Place p = twitter.saveGeoPlace(
                                                query.getName(),
                                                containedWithin,
                                                response.getToken(),
                                                
query.getLocation().getLatitude(),
                                                
query.getLocation().getLongitude(),
                                                attributes);

                                logger.debug( "place id:"+p.getId());

                        }

                } catch (TwitterException e) {
                        //currently failing with
                        //{"errors":[{"code":39,"message":"Creation token is 
missing or
invalid -- call similar_places to get a valid creation token"}]}
                        logger.error("cant add place",e);
                }
        }

}

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk

Reply via email to