javascript - How to check if a user likes my Facebook Page or URL using Facebook's API -



javascript - How to check if a user likes my Facebook Page or URL using Facebook's API -

i think i'm going crazy. can't work. want check if user has liked page javascript in iframe app.

fb.api({ method: "pages.isfan", page_id: my_page_id, }, function(response) { console.log(response); if(response){ alert('you likey'); } else { alert('you not likey :('); } } );

this returns: false i'm fan of page shouldn't homecoming true?!

i tore hair out on 1 too. code works if user has granted extended permission not ideal.

here's approach.

in nutshell, if turn on oauth 2.0 canvas advanced option, facebook send $_request['signed_request'] along every page requested within tab app. if parse signed_request can info user including if they've liked page or not.

function parsepagesignedrequest() { if (isset($_request['signed_request'])) { $encoded_sig = null; $payload = null; list($encoded_sig, $payload) = explode('.', $_request['signed_request'], 2); $sig = base64_decode(strtr($encoded_sig, '-_', '+/')); $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true)); homecoming $data; } homecoming false; } if($signed_request = parsepagesignedrequest()) { if($signed_request->page->liked) { echo "this content fans only!"; } else { echo "please click on button view tab!"; } }

javascript facebook facebook-graph-api

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -