Could you guys give me a little push here. I'm stuck trying to run the yelp api inside the onPerformSyn.
How can I possible do this.? I'm getting the error below. "No empty constructor"
I'm using this post to try to create the constructor but it doesn't work for me.
Please help is appreciated.
Note: After the Yelp response I'll be storing the data into SQLite (Scheme Library) so that is not the end of the code.
public class SyncAdapter extends AbstractThreadedSyncAdapter{
public final String LOG_TAG = SyncAdapter.class.getSimpleName();
public static final int SYNC_INTERVAL = 4;//60 * 180;
public static final int SYNC_FLEXTIME = SYNC_INTERVAL/3;
private static final long DAY_IN_MILLIS = 1000;//1000 * 60 * 60 * 24;
private static final int WEATHER_NOTIFICATION_ID = 3004;
private GoogleApiClient mGoogleApiClient;
private YelpAPI yelpAPI;
private Location mLastLocation;
public SyncAdapter(Context context, boolean autoInitialize) {
super(context, autoInitialize);
// YelpAPIFactory apiFactory = new YelpAPIFactory(BuildConfig.YELP_CONSUMER_KEY, BuildConfig.YELP_CONSUMER_SECRET, BuildConfig.YELP_TOKEN, BuildConfig.YELP_TOKEN_SECRET);
// yelpAPI = apiFactory.createAPI();
}
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
class YelpApi2 extends DefaultApi10a {
@Override
public String getAccessTokenEndpoint() {
return null;
}
@Override
public String getAuthorizationUrl(Token arg0) {
return null;
}
@Override
public String getRequestTokenEndpoint() {
return null;
}
}
class Yelp {
OAuthService service;
Token accessToken;
public Yelp(String consumerKey, String consumerSecret, String token, String tokenSecret) {
this.service = new ServiceBuilder().provider(YelpApi2.class).apiKey(consumerKey).apiSecret(consumerSecret).build();
this.accessToken = new Token(token, tokenSecret);
}
public String search(String term, double latitude, double longitude) {
OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.yelp.com/v2/search");
request.addQuerystringParameter("term", term);
request.addQuerystringParameter("ll", latitude + "," + longitude);
this.service.signRequest(this.accessToken, request);
Response response = request.send();
return response.getBody();
}
}
Yelp yelp = new Yelp(BuildConfig.YELP_CONSUMER_KEY, BuildConfig.YELP_CONSUMER_SECRET, BuildConfig.YELP_TOKEN, BuildConfig.YELP_TOKEN_SECRET);
String response = yelp.search("church", 30.361471, -87.164326);
System.out.println(response);
}
I followed this tut, but I didn't do the .jar part, i couldn't import it, instead I used this line in the gradle.
compile 'com.yelp.clientlib:yelp-android:2.0.0'
Error I'm getting
=========================================
FATAL EXCEPTION: SyncAdapterThread-1
Process: mem.edu.joshua, PID: 14149
org.scribe.exceptions.OAuthException: Error while creating the Api object
at org.scribe.builder.ServiceBuilder.createApi(ServiceBuilder.java:59)
at org.scribe.builder.ServiceBuilder.provider(ServiceBuilder.java:45)
at mem.edu.joshua.sync.SyncAdapter$1Yelp.<init>(SyncAdapter.java:99)
at mem.edu.joshua.sync.SyncAdapter.onPerformSync(SyncAdapter.java:116)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259)
Caused by: java.lang.InstantiationException: can't instantiate class mem.edu.joshua.sync.SyncAdapter$1YelpApi2; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
[1]: http://stackoverflow.com/questions/11859403/no-empty-constructor-when-create-a-service
[2]: https://thysmichels.com/2011/12/30/yelp-api-example/#comment-18031