本文整理汇总了Java中org.scribe.builder.api.FacebookApi类的典型用法代码示例。如果您正苦于以下问题:Java FacebookApi类的具体用法?Java FacebookApi怎么用?Java FacebookApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FacebookApi类属于org.scribe.builder.api包,在下文中一共展示了FacebookApi类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfoJSON
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
private JSONObject getUserInfoJSON(String code, String callBackUrl) {
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback(host + callBackUrl)
.scope("email")
.build();
Verifier verifier = new Verifier(code);
Token accessToken = service.getAccessToken(NULL_TOKEN, verifier);
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
request.addOAuthParameter("scope", "email");
service.signRequest(accessToken, request);
Response response = request.send();
LOG.info("response body is " + response.getBody());
try {
JSONObject obj = new JSONObject(response.getBody());
obj.put("access_token", accessToken.getToken());
return obj;
} catch (JSONException e) {
return new JSONObject();
}
}
示例2: FacebookOAuthService
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
@Inject
FacebookOAuthService(
PluginConfigFactory cfgFactory,
@PluginName String pluginName,
@CanonicalWebUrl Provider<String> urlProvider) {
PluginConfig cfg = cfgFactory.getFromGerritConfig(pluginName + CONFIG_SUFFIX);
String canonicalWebUrl = CharMatcher.is('/').trimTrailingFrom(urlProvider.get()) + "/";
service =
new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(cfg.getString(InitOAuth.CLIENT_ID))
.apiSecret(cfg.getString(InitOAuth.CLIENT_SECRET))
.callback(canonicalWebUrl + "oauth")
.scope(SCOPE)
.build();
}
示例3: login
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
/**
* Log in.
*
* @param key Facebook key
* @param secret Facebook secret
* @param tokenPath Path to save the token
* @param vCode How to get the verification code
* @throws IOException
* @throws InterruptedException
* @throws com.vaushell.superpipes.tools.scribe.fb.FacebookException
*/
public void login( final String key ,
final String secret ,
final Path tokenPath ,
final A_ValidatorCode vCode )
throws IOException , InterruptedException , FacebookException
{
loginImpl( FacebookApi.class ,
key ,
secret ,
"read_stream,publish_actions" ,
"http://www.facebook.com/connect/login_success.html" ,
false ,
tokenPath ,
vCode );
target = getMeID();
page = false;
}
示例4: loginAsPage
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
/**
* Log in as a page.
*
* @param pageName Page name (not the ID)
* @param key Facebook key
* @param secret Facebook secret
* @param tokenPath Path to save the token
* @param vCode How to get the verification code
* @throws IOException
* @throws InterruptedException
* @throws FacebookException
*/
public void loginAsPage( final String pageName ,
final String key ,
final String secret ,
final Path tokenPath ,
final A_ValidatorCode vCode )
throws IOException , InterruptedException , FacebookException
{
loginImpl( FacebookApi.class ,
key ,
secret ,
"read_stream,publish_actions,manage_pages" ,
"http://www.facebook.com/connect/login_success.html" ,
false ,
tokenPath ,
vCode );
target = getPageIDandChangeToken( pageName );
page = true;
}
示例5: loginURL
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
private String loginURL(@NonNull String redirectURL) {
Preconditions.checkArgument(redirectURL.startsWith("/"));
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback(host + redirectURL)
.scope("email")
.build();
return service.getAuthorizationUrl(null);
}
示例6: getInstanceFacebook
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
@Produces
@Facebook
public OAuthService getInstanceFacebook() {
this.service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(env.get(FACEBOOK_CLIENT_ID))
.apiSecret(env.get(FACEBOOK_APP_SECRET))
.callback(env.get("host")+env.get(FACEBOOK_REDIRECT_URI))
.build();
return service;
}
示例7: doAuth
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
@Override
protected void doAuth( Intent intent )
{
final String code = intent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
Token accessToken = null;
String userName = null;
try
{
OAuthService service = new ServiceBuilder()
.callback( FacebookLoginActivity.FACEBOOK_CALLBACK_URL )
.provider( FacebookApi.class )
.apiKey( FacebookConfig.FACEBOOK_OAUTH_APP_ID )
.apiSecret( FacebookConfig.FACEBOOK_OAUTH_APP_SECRET )
.build();
accessToken = service.getAccessToken( null, new Verifier( code ) );
OAuthRequest request = new OAuthRequest( Verb.GET, FACEBOOK_USERNAME_URL );
service.signRequest( accessToken, request );
Response response = request.send();
userName = Helper.extractJsonStringField( response.getBody(), "name" );
}
catch ( Exception e )
{
Helper.debug( "Failed to get Facebook access token : " + e.getMessage() );
}
boolean success = null != accessToken;
// Subscriber : FacebookLoginHandler : onFacebookAuthDone()
HashtaggerApp.bus.post( new FacebookAuthDoneEvent( success, accessToken, userName ) );
}
示例8: getProviderClass
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
@Override
protected Class<? extends Api> getProviderClass()
{
return FacebookApi.class;
}
示例9: main
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("You need to pass the Facebook API secret as a first parameter on the command-line!");
System.exit(-1);
}
String apiSecret = args[0];
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback("http://www.facebook.com/connect/login_success.html")
.build();
Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize Scribe here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
}
示例10: FacebookButton
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
public FacebookButton(String key, String secret) {
super(FacebookApi.class, key, secret);
setIcon(new ClassResource("/org/vaadin/addon/oauthpopup/icons/facebook16.png"));
setCaption("Facebook");
}
示例11: getApi
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
@Override
protected Class<? extends Api> getApi() {
return FacebookApi.class;
}
示例12: FacebookHandler
import org.scribe.builder.api.FacebookApi; //导入依赖的package包/类
public FacebookHandler() {
service = new ServiceBuilder().provider(FacebookApi.class)
.apiKey(APP_ID).apiSecret(APP_SECRET)
.callback("http://test.anycook.de/anycook/NewFacebookUser").build();
}