facebook erweiterte Berechtigungen
UPDATE 2:
OK, habe es "irgendwie" zu arbeiten, indem Sie ändern:
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream',
'next' => 'http://'.$_SERVER['SERVER_NAME'].'/success.php',
'cancel_url' => 'http://'.$_SERVER['SERVER_NAME'].'/cancel.php'
));
zu diesem:
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream',
'next' => 'http://'.$_SERVER['SERVER_NAME'].'/success.php',
'cancel_url' => 'http://'.$_SERVER['SERVER_NAME'].'/cancel.php'
));
header('Location: '.$loginUrl);
also ich habe den header('Location: '.$loginUrl);
.
Aber die Seite ist seltsam verhält. Ich navigieren Sie zu der Seite, login, und aktualisieren Sie dann die Seite erneut anmelden, dann fragt mich um Erlaubnis zu posten zu der Seite, und schließlich Beiträge auf der Seite.
Warum muss ich bei der Anmeldung zweimal?
UPDATE 1:
Ich habe jetzt folgenden script, das scheint nicht zu funktionieren. In diesem Zustand, ich versuche nur, um post an meine eigene Wand, aber irgendwann möchten post an Freunde Wand zu:
<?php
/**
*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
require 'facebook.php';
//Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '<appId removed for security reasons>',
'secret' => '<secret removed for security reasons>',
'cookie' => true,
));
//We may or may not have this data based on a $_GET or $_COOKIE based session.
//
//If we get a session here, it means we found a correctly signed session using
//the Application Secret only Facebook and the Application know. We dont know
//if it is still valid until we make an API call using the session. A session
//can become invalid if it has already expired (should not be getting the
//session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();
$me = null;
//Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$post = $facebook->api("/me/feed", "POST", array('message' => 'Hello! I\'m using the FB Graph API!'));
} catch (FacebookApiException $e) {
error_log($e);
}
}
//login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream',
'next' => 'http://'.$_SERVER['SERVER_NAME'].'/success.php',
'cancel_url' => 'http://'.$_SERVER['SERVER_NAME'].'/cancel.php'
));
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<!--
We use the JS SDK to provide a richer user experience. For more info,
look here: http://github.com/facebook/connect-js
-->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>, //don't refetch the session when PHP already has it
status : true, //check login status
cookie : true, //enable cookies to allow the server to access the session
xfbml : true //parse XFBML
});
//whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<h1><a href="example.php">php-sdk</a></h1>
<?php if ($me): ?>
<a href="<?php echo $logoutUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php else: ?>
<div>
Using JavaScript & XFBML: <fb:login-button></fb:login-button>
</div>
<?php endif ?>
<h3>Session</h3>
<?php if ($me): ?>
<pre><?php print_r($session); ?></pre>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $uid; ?>/picture">
<?php echo $me['name']; ?>
<h3>Your User Object</h3>
<pre><?php print_r($me); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>
Bekomme ich die folgende Fehlermeldung:
[Wed Apr 27 22:28:16 2011] [error] [client <ip address removed for security reasons>] OAuthException: (#200) The user hasn't authorized the application to perform this action, referer: http://<ip address removed for security reasons>/index.php
URSPRÜNGLICHEN FRAGE:
Habe ich die folgenden arbeiten Skript, welches erlaubt jemanden zu anmelden, um meine Seite mit Ihrem facebook-details, dann kann ich das erfassen Ihrer access_token also ich kann mit der Grafik-api:
<?php
/**
*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
require 'facebook.php';
//Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'app id goes here',
'secret' => 'secret id goes here',
'cookie' => true,
));
//We may or may not have this data based on a $_GET or $_COOKIE based session.
//
//If we get a session here, it means we found a correctly signed session using
//the Application Secret only Facebook and the Application know. We dont know
//if it is still valid until we make an API call using the session. A session
//can become invalid if it has already expired (should not be getting the
//session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();
$me = null;
//Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
//login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<!--
We use the JS SDK to provide a richer user experience. For more info,
look here: http://github.com/facebook/connect-js
-->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>, //don't refetch the session when PHP already has it
status : true, //check login status
cookie : true, //enable cookies to allow the server to access the session
xfbml : true //parse XFBML
});
//whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<h1><a href="example.php">php-sdk</a></h1>
<?php if ($me): ?>
<a href="<?php echo $logoutUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php else: ?>
<div>
Using JavaScript & XFBML: <fb:login-button></fb:login-button>
</div>
<?php endif ?>
<h3>Session</h3>
<?php if ($me): ?>
<pre><?php print_r($session); ?></pre>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $uid; ?>/picture">
<?php echo $me['name']; ?>
<h3>Your User Object</h3>
<pre><?php print_r($me); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>
Sobald der Benutzer sich angemeldet hat, ich verstehe das, ich kann eine Liste mit Ihren Freunden über:
https://graph.facebook.com/me/friends?access_token=...
Was ich kann nicht herausfinden, wie die Nutzung erweiterter Berechtigungen, so dass meine app posten kann der Benutzer Freunde facebook Wänden.
Ich bin offenbar soll die Nutzung erweiterter Berechtigungen, plus die folgenden:
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
Ich verstehe nicht, wie ich bin, dies zu tun von PHP.
- mögliche Duplikate von brauche Hilfe zum buchen auf Benutzer-wall
Du musst angemeldet sein, um einen Kommentar abzugeben.
Update:
Gut kann ich nicht wirklich testen Sie es selbst, also einfach ein paar Vorschläge, was man versuchen könnte. Ändern Sie die
$loginUrl
dieser:In den ganzen Kontext, der Anfang der Datei sollte wie folgt Aussehen:
Gut, überprüfen Sie zunächst, ob Sie eine Sitzung, deshalb benötigen Sie zum konfigurieren des Facebook SDK, wie in dem Beispiel:
Dann können Sie überprüfen, ob der Benutzer angemeldet ist und Ihre app autorisiert wurde:
In der
if
-Klausel, die Sie dann zu tun haben, einen redirect auf die richtige login-url, um alle Berechtigungen, die Sie benötigen:Nachdem Sie die Berechtigungen, die Sie veröffentlichen können, wie in der Dokumentation erwähnt durch die Verwendung
In der Dokumentation für Facebook zeigt der raw-Umsetzung für die Erreichung dieses, was ist der curl-Aufruf, die Sie eingefügt. Dies ist im Grunde nur zeigen, Funktionalität und ist nicht wirklich erklärend darüber, wie die Aufgabe in Ihrer Sprache der Wahl.
Als Michael Rose wies darauf hin, unten, müssen Sie, zunächst Fragen Sie nach der erweiterten Berechtigung zum posten auf den Benutzer' Wand. Um dies zu tun, Ihre $loginUrl-Aufruf sollte so Aussehen:
Dieser wird der Benutzer aufgefordert, die Anwendung zu installieren und Ihnen den Zugriff auf die publish_stream erweiterte Berechtigung, die erforderlich ist, um post an Ihre Wand und Ihre Freunde Wände.
Ist, um tatsächlich MACHEN die Pinnwand schreiben, wird Ihr code wird etwas ähnliches wie dies:
Sollten Sie dies auf einem POST-request, oder einige Anforderung an eine Seite (auch eine ajax-Anfrage, wenn Sie möchten), nachdem Sie die Erlaubnis des Benutzers. Die FB-PHP-SDK sollte automatisch abholen Ihrer Benutzer ein Zugriffstoken, das zu prüfen, und stellen Sie die Anfrage für Sie.
Versuchen Sie, aus
zu
Ich weiß nicht mehr wo, aber irgendwo habe ich mal gelesen, dass man die Weiterleitung per javascript. Ziemlich langer Zeit habe ich gelesen, dass, so es verändert haben könnte.