-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
110 lines (107 loc) · 5.52 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<html>
<head>
<title>AnyMeta OAuth Test</title>
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="oauth.js"></script>
<script type="text/javascript" src="anymeta.js"></script>
<script type="text/javascript">
// a helper function to append an unordered list of the given object's keys and values to the provided DOM element
function listObject(obj, appendMe) {
var ul = document.createElement('ul');
for (var k in obj) {
if (obj[k] instanceof Object && !(obj[k] instanceof String)) {
var li = document.createElement('li');
li.innerHTML = k + ':';
ul.appendChild(li);
listObject(obj[k], ul);
} else {
var li = document.createElement('li');
li.innerHTML = k + ': ' + obj[k];
ul.appendChild(li);
}
}
appendMe.appendChild(ul);
}
function onLoad() {
// see if we already have the tokens stored
AnyMeta.currentSite = 'mediamatic.net';
// localStorage.clear();
var auth_token = localStorage.getItem(AnyMeta.currentSite + '.oauth_token');
var auth_token_secret = localStorage.getItem(AnyMeta.currentSite + '.oauth_token_secret');
// getItem returns null if the key does not exist, so check that we have both values
if (auth_token && auth_token_secret) {
AnyMeta.setTokens(auth_token, auth_token_secret);
AnyMeta.user.info(
function (person) { // the success callback
var h1 = document.createElement('h1');
h1.innerHTML = 'Welcome <a href="http://www.mediamatic.net/person/' + person.id + '/en">' + person.title + '</a>!';
document.body.appendChild(h1);
listObject(person, document.body);
/*
AnyMeta.user.create(
'The Foundry',
function (result) {
var h1 = document.createElement('h1');
h1.innerHTML = 'Created a new user!';
document.body.appendChild(h1);
listObject(result, document.body);
}
);
*/
AnyMeta.predicates.get(
'MEDIAMATIC',
['text.title', 'text.body'],
function (thing) {
var h1 = document.createElement('h1');
h1.innerHTML = 'anymeta.predicates.get';
document.body.appendChild(h1);
listObject(thing, document.body);
},
function (err) {
console.log('error! ' + err.responseText.toString());
}
);
}
);
} else {
// try to register for the following server with callback and errback
AnyMeta.register(
// once the system is ready to hand off to us to have the user authorize us on the AnyMeta site in question
// url is the url the user should visit to authorize us
// callback is the function we should call once the user says they have successfully authorized us
// it should be called with a callback and errback
// there is no errback as the library doesn't need to do anything on to authorize
function (url, callback) {
alert("Please go to " + url + '\nWhen done click ok.');
callback(
function (tokens) {
// persist for later (don't use cookies because they'll get passed around and in plain text)
localStorage.setItem(AnyMeta.currentSite + '.oauth_token', tokens['oauth_token']);
localStorage.setItem(AnyMeta.currentSite + '.oauth_token_secret', tokens['oauth_token_secret']);
AnyMeta.setTokens(tokens['oauth_token'], tokens['oauth_token_secret']);
AnyMeta.user.info(
function (person) { // the success callback
var h1 = document.createElement('h1');
h1.innerHTML = 'Welcome <a href="http://www.mediamatic.net/person/' + person.id + '/en">' + person.title + '</a>!';
document.body.appendChild(h1);
listObject(person, document.body);
}
);
},
function (badRequest) {
console.log('Failed to get an access token.');
}
);
},
function (badRequest) {
console.log('Failed to get a request token.');
}
);
}
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>